【发布时间】:2015-04-30 10:25:55
【问题描述】:
考虑一下这个 WinForms 程序:
Module Main
Dim notifyicon As New System.Windows.Forms.NotifyIcon
'Dim dummycontrol As New System.Windows.Forms.Control
Public Sub Main()
If (System.Threading.SynchronizationContext.Current Is Nothing) Then
MessageBox.Show("Nothing")
Else
MessageBox.Show("Something")
End If
End Sub
End Module
NotifyIcon 是一个 WinForm 控件,需要一个消息循环,那么为什么声明 dummycontrol(或任何 WinForms 控件)会设置 SynchronizationContext,而 NotifyIcon 却没有?
【问题讨论】:
-
NotifyIcondoesn't inherit fromSystem.Windows.Forms.Control- 这会改变你问题的前提吗? -
@JamesThorpe 谢谢;肯定是一个有说服力的观察,并解释了为什么它没有表现出与其他控件相同的行为,但我仍然很好奇为什么尽管如此不会设置上下文。
标签: .net vb.net winforms synchronizationcontext