How does .NET ExecutionContext actually work?

霸气de小男生 提交于 2019-12-05 06:29:30

That's pretty misleading documentation. I can't answer the broader thrust of your question, but I can tell you why SynchronizationContext does't flow.

If you look at the source of Thread.Start, it eventually calls down to:

    [SecuritySafeCritical]
    private void Start(ref StackCrawlMark stackMark)
    {
      this.StartupSetApartmentStateInternal();
      if (this.m_Delegate != null)
        ((ThreadHelper) this.m_Delegate.Target).SetExecutionContextHelper(ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.IgnoreSyncCtx));
      this.StartInternal(CallContext.Principal, ref stackMark);
    }

Note that it explicitly passes ExecutionContext.CaptureOptions.IgnoreSyncCtx by default. It also passes CallContext.Principal regardless of ExecutionContext.SuppressFlow(). So, the explains why you are seeing what you are seeing, but not when it might be useful or why the docs are flat out wrong!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!