.NET threading - How
to create and manage threads - March 13, 2009 at 15:20 PM by Amit Satpute
Explain how to create and manage threads using Thread class in the
System.Threading namespace in .NET.
using System.Threading;
private void ThreadTask()
{
int x;
int val;
Random r=new Random();
while(true)
{
x=this.progressBar1.Step*r.Next(-1,2);
val =
this.progressBar1.Value + x;
if (val >
this.progressBar1.Maximum)
val = this.progressBar1.Maximum;
else if (val
< this.progressBar1.Minimum)
val = this.progressBar1.Minimum;
this.progressBar1.Value
= val;
Thread.Sleep(100);
}
}
You need to write these lines first:
Thread t1 = new Thread(new ThreadStart(this.ThreadTask));
t1.IsBackground = true;
t1.Start();
|