Is there a way to make async / wait for a continuation in the first available stream?

One of the interesting things about C # 5.0 is the async/await keywords and how it simplifies the plumbing that you used to record using the parallel task library (TPL).

My question is if you have the thread-agnostic attribute and you start the async operation in the main thread (read: user interface thread), but you don’t have to if the continuation happens in the main thread, then you can tell the async/await paradigm async/await , what do you want it to continue in the first available thread, even if it is not the main thread?

I would think that being able to do this would greatly increase the effectiveness of certain scenarios, but not a silver bullet.

+6
source share
1 answer

If you don't care when the rest of the method continues, use Task.ConfigureAwait :

 await foo.DoSomethingAsync().ConfigureAwait(continueOnCapturedContext: false); 

(Here you do not need to use a named argument, but it increases clarity.)

See the "Configuring Context" section for more information .

+15
source

Source: https://habr.com/ru/post/951664/


All Articles