什么“当前"属性与 ExecutionContext 一起流动 [英] What "Current" properties flow with ExecutionContext
问题描述
这是一个由两部分组成的问题:
This is a two part question:
谁能提供一个 ASP.NET/.NET 属性的列表,这些属性通常是与 ExecutionContext 一起流动的本地线程?
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?
HttpContext.Current? Thread.CurrentContext? Thread.CurrentPrincipal? Thread.CurrentCulture?
我可以依靠哪些属性来生存/持久化 async/await?
What properties can I count on surviving/persisting async/await?
还有什么?
有什么方法可以添加特定于应用程序的上下文信息,这些信息将随 ExecutionContext 自动流动?类似的东西
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;
推荐答案
最好的资源是 ExecutionContext vs. SynchronizationContext 作者:Stephen Toub.没有您正在寻找的属性列表.
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 实际上使用 SynchronizationContext
来传输 HttpContext.Current
和 对待Thread.CurrentPrincipal
相当奇怪.
ASP.NET actually uses SynchronizationContext
to flow HttpContext.Current
, and treats Thread.CurrentPrincipal
rather oddly.
您可以使用 LogicalSetData
/LogicalGetData
添加您自己的上下文.但是,您应该只存储不可变数据.我在在我的博客上记录了这一点.
You can add your own context using LogicalSetData
/LogicalGetData
. However, you should only store immutable data. I document this on my blog.
这篇关于什么“当前"属性与 ExecutionContext 一起流动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!