How to update control value in C# Thread.
Use below sample of code:
Thread t1=new Thread();
String b="";
int all=0;
private void button5_Click(object sender, EventArgs e)
{
t1 = new Thread(new ThreadStart(MyCodeRun)); t1.Start();
}
void MyCodeRun()
{
while (String.IsNullOrEmpty(b) || String.IsNullOrWhiteSpace(b))
{
this.BeginInvoke(new MethodInvoker(changeValue));
all = all + 1;
System.Threading.Thread.Sleep(1000);
}
}
private void changeValue()
{
label1.Text =all + "";
}
Use below sample of code:
Thread t1=new Thread();
String b="";
int all=0;
private void button5_Click(object sender, EventArgs e)
{
t1 = new Thread(new ThreadStart(MyCodeRun)); t1.Start();
}
void MyCodeRun()
{
while (String.IsNullOrEmpty(b) || String.IsNullOrWhiteSpace(b))
{
this.BeginInvoke(new MethodInvoker(changeValue));
all = all + 1;
System.Threading.Thread.Sleep(1000);
}
}
private void changeValue()
{
label1.Text =all + "";
}
0 comments:
Post a Comment