Everyone, As we know, "ThreadPool" is a static type, so we can't "new" a "ThreadPool. If I use the code
BackgroundWorker worker = new BackgroundWorker();
how am I supposed to add this "workers" to "ThreadPool"? Thanks
Everyone, As we know, "ThreadPool" is a static type, so we can't "new" a "ThreadPool. If I use the code
BackgroundWorker worker = new BackgroundWorker();
how am I supposed to add this "workers" to "ThreadPool"? Thanks
You don't. Check the following example:
public Form1()
{
InitializeComponent();
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
}
private void startAsyncButton_Click(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy != true)
{
// Start the asynchronous operation.
backgroundWorker1.RunWorkerAsync();
}
}
See the call to RunWorkerAsync
. This handles the asynchronous execution of the background process, without you worrying about the thread pool.
More hands on information about how WPF and .net chose threads behind the scenes, can be found here: How does BackgroundWorker decide on which thread to run the RunWorkerCompleted handler?