I have some hub methods that perform I/O operations which I want to call asynchronously.
Is it safe to use ConfigureAwait(false)
in my hub methods, or does SignalR require a captured SynchronizationContext for request info or something like that?
public async Task<Response> Save() {
// do some prep work
var response = await SaveThingsAsync().ConfigureAwait(false);
// do something with response
return response;
}
To clarify: my code does not require thread culture or anything else stored in the SynchronizationContext.
My concern is that the SignalR server code might store information there, such as Client Ids, request infos or the like, which it may not be able to access if the async method is continued from a different thread.
When I tested my method it appeared to work fine, but that doesn't proof anything necessarily.
ConfigureAwait does not remove the sync context. It merely causes the task completion continuation to not use the current sync context.
It is always safe to use if the rest of the current async method does not depend on the sync context. Emphasis on method as opposed to thread.
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