Can I use ConfigureAwait (false) `in SignalR hubs or does the SignalR infrastructure rely on SynchronizationContext?

I have some hub methods that perform I / O operations that I want to call asynchronously.

Is it possible to use a ConfigureAwait(false)hub in my methods or for SignalR I need a captured SynchronizationContext for request information 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 a thread culture or anything else stored in a SynchronizationContext.
I am concerned that the SignalR server code might store there information, such as client identifiers, request information or the like, that might not be available if the asynchronous operation method continues from another thread.

When I tested my method, it worked fine, but that doesn't prove anything.

+4
source share
2 answers

Signal R is independent of SynchronizationContext. Typically, it is hosted in Win32 services (and console testing applications), where not SynchronizationContext.

See also this problem with SignalR .

+3
source

ConfigureAwait does not remove the synchronization context. This simply leads to continued completion of the task so as not to use the current synchronization context.

It is always safe to use if the rest of the current asynchronization method is independent of the synchronization context. Emphasis on the method, as opposed to flow.

+4
source

All Articles