C#.NET : Creating a worker thread in C#.NET?
How can we create a worker thread in C#.NET? You can use the component BackgroundWorker
Drag and drop the component into your form and double click the object a function is create like below,
You can put your code inside this function and make sure you won't be accessing a object that
is being used by the main thread.
To start the thread call,
backgroundWorker1.RunWorkerAsync();
and to support cancellation of thread you must set this property,
backgroundWorker1.WorkerSupportsCancellation = true;
and to cancel the thread call,
backgroundWorker1.CancelAsync();
That's it!
Comments
Post a Comment