Click here to Skip to main content
15,671,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I have a progress bar and label to indicate the progress of execution. but progress value and label text is not printing as expected. In each of the method i assign the value and text to static property which can be accessed from the UI.
Problem is, initial text is not showed and its stuck with "Post Expense completed". Please help me to display the label message and progress bar sequentially.

Main Method which calling from UI
public class MainMethod
        public static void PostData(DataSet ds, PostBasicInput pbi)
            Task t1 = Task.Factory.StartNew(() => TaskClass.PostBasicPlan(ds, pbi)).ContinueWith((prevtask) => TaskClass.PostMembers(ds, pbi));
            Task.Factory.StartNew(() => TaskClass.PostIncome(ds, pbi));
            Task.Factory.StartNew(() => TaskClass.PostExpense(ds, pbi));

public class TaskClass
       public static void PostBasicPlan(DataSet ds, PostBasicInput pbi)
           TestSettings.progresstext = "Post basic started";
           TestSettings.progressvalue = 10;
           TestSettings.progresstext = "Post basic completed";
           TestSettings.progressvalue = 20;
       public static void PostMembers(DataSet ds, PostBasicInput pbi)
           TestSettings.progresstext = "Post Member  started";
           TestSettings.progressvalue = 30;
           TestSettings.progresstext = "Post Member completed";
           TestSettings.progressvalue = 40;
       public static void PostIncome(DataSet ds, PostBasicInput pbi)
           TestSettings.progresstext = "Post income started";
           TestSettings.progressvalue = 50;
           TestSettings.progresstext = "Post income completed";
           TestSettings.progressvalue = 60;
       public static void PostExpense(DataSet ds, PostBasicInput pbi)
           TestSettings.progresstext = "Post expense started";
           TestSettings.progressvalue = 70;
           TestSettings.progresstext = "Post expense completed";
           TestSettings.progressvalue = 80;
       public static void PopulateExcel(String excelpath)
           TestSettings.progresstext = "Excel file creation";
           TestSettings.progresstext = "Excel Generated sucessfully";
           TestSettings.progressvalue = 90;
       public static void Results(String apipath)
           TestSettings.progresstext = "Calling result API";
           TestSettings.progresstext = "Actual vs expected excel generated";
           TestSettings.progressvalue = 100;

Additional classes
public class PostBasicInput
      public string excelId { get; set; }
      public int planId { get; set; }
      public string timeverificationstamp { get; set; }
  public class TestSettings
      public static int progressvalue { get; set; }
      public static string progresstext { get; set; }

What I have tried:

Button click event
  private void button1_Click(object sender, EventArgs e)
            DataSet ds=new DataSet();
            PostBasicInput pbi=new PostBasicInput();
            Task t1= Task.Factory.StartNew(()=> MainMethod.PostData(ds, pbi));
            Task t2 = Task.Factory.StartNew(() => TaskClass.PopulateExcel("xyz"));
            Task.WaitAll(t1, t2);
            lblmsg.Text = "Completed..";
//timer tick event
        private void timer1_Tick(object sender, EventArgs e)
            progressBar1.Value = TestSettings.progressvalue;
            lblmsg.Text = TestSettings.progresstext;
Updated 7-Aug-16 2:38am
Kornfeld Eliyahu Peter 7-Aug-16 8:38am    
Do you try to update the UI from a different thread?
jinesh sam 7-Aug-16 8:45am    
yes its separate thread
Kornfeld Eliyahu Peter 7-Aug-16 8:50am    
That's your problem! There is some problems, with that called 'thread safety'...
There are lot of articles if you search Google right...
May you start here:
RickZeeland 7-Aug-16 10:23am    
I would make the class TestSettings static too.
Also I would use progressBar1.InvokeRequired in timer1_Tick().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900