为什么在我的WinForms应用SynchronizationContext.Current空? [英] Why is SynchronizationContext.Current null in my Winforms application?

查看:104
本文介绍了为什么在我的WinForms应用SynchronizationContext.Current空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚写代码:

System.Threading.SynchronizationContext.Current.Post(
    state => DoUpdateInUIThread((Abc)state), 
    abc);



但System.Threading.SynchronizationContext.Current为空

but System.Threading.SynchronizationContext.Current is null

推荐答案

请参见这个解释

SynchronizationContext.Current只在主线程设置(这是你实际上并不需要它的唯一的线程)

SynchronizationContext.Current is only set in the main thread (which is the only thread where you don't actually need it)

博客文章提出了一种解决方法。

The blog post proposes a workaround.

这篇关于为什么在我的WinForms应用SynchronizationContext.Current空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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