複数のスレッド化されたフォームを MDIChild として持つことは可能ですか? 多くの処理 CPU を必要とする MdiChild 形式の ActiveX コントロールがあり、以下のサンプル コードを使用して、あるコントロールが別のコントロールに影響を与えないようにしたいと考えています。しかし、行 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