Should I use ConfigureAwait (false) while waiting for IAsyncAction?

It is recommended, for example, here to make the most of ConfigureAwait(false)expected tasks.

Does this recommendation also apply to methods returning IAsyncAction, for example StreamSocket.ConnectAsync()?

That is, instead of just writing this in my class library:

await socket.ConnectAsync(hostName, port);

Should I write this?

await socket.ConnectAsync(hostName, port).AsTask().ConfigureAwait(false);
+4
source share
1 answer

Yes. It is best to use any method that does not need its context, use ConfigureAwait(false). The configuration is for await(and not Taskor IAsyncAction), and there must be configured await.

+5

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


All Articles