Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What "Current" properties flow with ExecutionContext

This is a two part question:

  1. Can someone provide a list of the ASP.NET/.NET properties that are typically thread local that flow with ExecutionContext?

    HttpContext.Current? Thread.CurrentContext? Thread.CurrentPrincipal? Thread.CurrentCulture?

    What properties can I count on surviving/persisting async/await?

    What else?

  2. Is there any way to add application specific Context information that will flow automatically with ExecutionContext? Something like

    var ec = ExecutionContext.Capture();
    ec.CustomContext["MyCustomContext"] = ACustomContext;
    
like image 696
Joe Enzminger Avatar asked Jun 21 '13 18:06

Joe Enzminger


1 Answers

The best resource for this is ExecutionContext vs. SynchronizationContext by Stephen Toub. There is no list of properties like what you're looking for.

ASP.NET actually uses SynchronizationContext to flow HttpContext.Current, and treats Thread.CurrentPrincipal rather oddly.

You can add your own context using LogicalSetData/LogicalGetData. However, you should only store immutable data. I document this on my blog.

like image 147
Stephen Cleary Avatar answered Dec 06 '22 16:12

Stephen Cleary