Skip to content

Support AspNetSynchronizationContext#5

Open
Bouke wants to merge 1 commit into
ramondeklein:masterfrom
Bouke:fix/issue-3-aspnet
Open

Support AspNetSynchronizationContext#5
Bouke wants to merge 1 commit into
ramondeklein:masterfrom
Bouke:fix/issue-3-aspnet

Conversation

@Bouke

@Bouke Bouke commented Dec 10, 2020

Copy link
Copy Markdown

ASP.NET uses ISyncContextLock for synchronization, which resets the sychronization context after an await.

I've created these changes mostly be trial and error. It seems to work for me, but YMMV.

In ASP.NET MVC 5 try the following:

public ActionResult Index()
{
    TestAsync().Wait();
}

public async Task TestAsync()
{
    Debug.WriteLine($"TestAsync[0]: {SynchronizationContext.Current}");

    await Task.Yield();
    Debug.WriteLine($"TestAsync[1]: {SynchronizationContext.Current}");

    await Task.Delay(1_000).ConfigureAwait(false);
    Debug.WriteLine($"TestAsync[3]: {SynchronizationContext.Current}");
}

In additional testing, I've found some blocking situations that went undetected. Again, YMMV.

AspNet uses ISyncContextLock for synchronization, which resets the sychronization context after an await.
@Bouke Bouke changed the title Support AspNetSynchronizationContext (fixes issue #3) Support AspNetSynchronizationContext Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant