是否可以有多个线程形式作为 MDIChild?我有一个 MdiChild 形式的 ActiveX 控件,它可能会占用大量处理 CPU,并且希望通过使用下面的示例代码使一个控件不会影响另一个控件。但是行 frmDoc.MdiParent = Me 会引发跨线程异常。
Dim frmDoc As MDIChild
Dim newThread As New Thread(
Sub()
frmDoc = New MDIChild
frmDoc.MdiParent = Me '<- this line throws cross threading exception.
Application.Run(frmDoc)
End Sub
)
newThread.IsBackground = True
newThread.SetApartmentState(ApartmentState.STA)
newThread.Start()
引发 System.InvalidOperationException 未处理:
Message=Cross-thread operation not valid:
Control 'FormMdiApp' accessed from a thread other than the thread it was created on.
Source=System.Windows.Forms