【发布时间】:2017-07-12 09:47:24
【问题描述】:
SynchronizationContext.Current 在主线程上为空,我很难弄清楚这一点。
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
var ctx = System.Threading.SynchronizationContext.Current;
// ctx is null here
}
}
我在 .NET 4.6.1 上运行。它是一个混合的 Winforms 和 WPF 应用程序。入口点是 WinForms。以下是此类证据的一些截图:
它也与 this 之类的帖子无关,因为我使用的是较新的 .NET 版本,并且似乎提到的问题已经修复。还有什么好主意吗?
【问题讨论】:
-
SynchronizationContext.Current 究竟在哪里?提问时请提供您的问题的回购:stackoverflow.com/help/mcve
-
@mm8 - 已更新。 VladimirArustamian - 这不是我的情况。我在原始帖子的最后一段中提到了这一点。
标签: c# wpf multithreading winforms synchronizationcontext