I tried to use the following code to run some task in thread pool:
private async void button1_Click(object sender, EventArgs e)
{
await test().ConfigureAwait(continueOnCapturedContext: false);
}
private Task test()
{
Thread.Sleep(100000);
return null;
}
The code is supposed to run in the threadpool, however the current UI thread is still being blocked.
So can anyone help to take a look? thanks,
The code is supposed to run in the threadpool
No, that is not at all true. async does not run your code on a thread pool thread.
I suggest you read my async intro, which explains what async does do, and the official async FAQ, which addresses the thread pool misconception specifically:
Does the “async” keyword cause the invocation of a method to queue to the ThreadPool? To create a new thread? To launch a rocket ship to Mars?
No. No. And no.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With