none
IN Async/await, Will the thread that handles the completion of the operation have all the same state? RRS feed

  • Question

  • I've heard that the executionContext flows from the thread that started the async operation, to the thread that handles its completion. I'm wodering, in web api, does HttpContext, RequestContext, Thread.CurrentPrincipal, Thread.CurrentContext, etc all have the same data copied over when the completion handling thread begins executing?

    Along those lines, If I authenticated a user and set the principal to REquestContext.Principal in an async action, I assume that this context would flow to the thread that handles the continuation of the operation after it comes back and the data I put on the REquestContext would be the same.

    thanks all!

     
    Monday, June 29, 2015 2:23 AM

Answers

  • Hello,

    >>I'm wodering, in web api, does HttpContext, RequestContext, Thread.CurrentPrincipal, Thread.CurrentContext, etc all have the same data copied over when the completion handling thread begins executing?

    There is not a document which clear shows what the executionContext exactly flows, and for the resource about executionContext, the blog written by Stephen Toub should be helpful:

    http://blogs.msdn.com/b/pfxteam/archive/2012/06/15/executioncontext-vs-synchronizationcontext.aspx

    >> I assume that this context would flow to the thread that handles the continuation of the operation after it comes back and the data I put on the REquestContext would be the same.

    I suggest you could just have a try your assumption.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 30, 2015 6:47 AM
    Moderator

All replies

  • Hello,

    >>I'm wodering, in web api, does HttpContext, RequestContext, Thread.CurrentPrincipal, Thread.CurrentContext, etc all have the same data copied over when the completion handling thread begins executing?

    There is not a document which clear shows what the executionContext exactly flows, and for the resource about executionContext, the blog written by Stephen Toub should be helpful:

    http://blogs.msdn.com/b/pfxteam/archive/2012/06/15/executioncontext-vs-synchronizationcontext.aspx

    >> I assume that this context would flow to the thread that handles the continuation of the operation after it comes back and the data I put on the REquestContext would be the same.

    I suggest you could just have a try your assumption.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 30, 2015 6:47 AM
    Moderator
  • thank you.

    Yes, what I found online it didnt explicitly say what exactly was flowed using executionContext but just that it 'flowed'.

    Tuesday, June 30, 2015 5:08 PM