什么"电流和QUOT;性能流着的ExecutionContext [英] What "Current" properties flow with ExecutionContext

查看:161
本文介绍了什么"电流和QUOT;性能流着的ExecutionContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题的两个部分:

  1. 有人可以提供ASP.NET/.NET属性列表,通常线程本地与执行上下文流?

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

    什么样的​​属性,我可以指望尚存/持续异步/计谋?

    还有什么呢?

  2. 有没有什么办法可以添加应用程序特定的上下文信息,将与执行上下文自动流向?类似于

      VAR EC = ExecutionContext.Capture();
    ec.CustomContext [MyCustomContext] = ACustomContext;
     

解决方案

这样做的最好的资源是<一个href="http://blogs.msdn.com/b/pfxteam/archive/2012/06/15/executioncontext-vs-synchronizationcontext.aspx">ExecutionContext主场迎战的SynchronizationContext 通过斯蒂芬Toub。有属性像你所要寻找的没有列表。

ASP.NET实际上使用的SynchronizationContext 流入 HttpContext.Current 和<一href="http://www.hanselman.com/blog/SystemThreadingThreadCurrentPrincipalVsSystemWebHttpContextCurrentUserOrWhyFormsAuthenticationCanBeSubtle.aspx">treats Thread.CurrentPrincipal中,而奇怪的是。

您可以通过添加自己的上下文 LogicalSetData / LogicalGetData 。然而,你应该只存储不可变数据。我记录此在我的博客

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;
    

解决方案

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.

这篇关于什么&QUOT;电流和QUOT;性能流着的ExecutionContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆