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.WaitAny(t1);
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;
Thread.Sleep(2000);
TestSettings.progresstext = "Post basic completed";
TestSettings.progressvalue = 20;
}
public static void PostMembers(DataSet ds, PostBasicInput pbi)
{
TestSettings.progresstext = "Post Member started";
TestSettings.progressvalue = 30;
Thread.Sleep(2000);
TestSettings.progresstext = "Post Member completed";
TestSettings.progressvalue = 40;
}
public static void PostIncome(DataSet ds, PostBasicInput pbi)
{
TestSettings.progresstext = "Post income started";
TestSettings.progressvalue = 50;
Thread.Sleep(2000);
TestSettings.progresstext = "Post income completed";
TestSettings.progressvalue = 60;
}
public static void PostExpense(DataSet ds, PostBasicInput pbi)
{
TestSettings.progresstext = "Post expense started";
TestSettings.progressvalue = 70;
Thread.Sleep(2000);
TestSettings.progresstext = "Post expense completed";
TestSettings.progressvalue = 80;
}
public static void PopulateExcel(String excelpath)
{
TestSettings.progresstext = "Excel file creation";
Thread.Sleep(2000);
TestSettings.progresstext = "Excel Generated sucessfully";
TestSettings.progressvalue = 90;
}
public static void Results(String apipath)
{
TestSettings.progresstext = "Calling result API";
Thread.Sleep(2000);
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();
timer1.Start();
Task t1= Task.Factory.StartNew(()=> MainMethod.PostData(ds, pbi));
Task t2 = Task.Factory.StartNew(() => TaskClass.PopulateExcel("xyz"));
Task.WaitAll(t1, t2);
TaskClass.Results("http://");
lblmsg.Text = "Completed..";
}
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Value = TestSettings.progressvalue;
lblmsg.Text = TestSettings.progresstext;
}