Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created June 5, 2012 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tugberkugurlu/2878730 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/2878730 to your computer and use it in GitHub Desktop.
public async Task<ActionResult> Foo() {
//some sync stuff
//runs the async method
var foobar = await _someClass.GetAsync();
//this continuation ends up in another thread.
//cannot access some static instances such as HttpContext.Current
doSomeWork();
//some other stuff
}
@tugberkugurlu
Copy link
Author

This might be the solution?

SynchronizationContext.Current.Post((state) => {

    //...

}, TaskScheduler.FromCurrentSynchronizationContext());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment