我正在與消息Cross-thread operation not valid..
出現InvalidOperationException內的BeginInvoke
的_waitForm
的InvalidOperationException
在主窗體的構造函數創建。截圖中的方法從另一個線程中調用。我雖然這是什麼BeginInvoke
解決。我知道我是從另一個線程訪問窗體而不是創建窗體。 關於如何解決這個問題的任何想法?
這裏是堆棧跟蹤:
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.get_ContainsFocus()
at System.Windows.Forms.Control.SelectNextIfFocused()
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Hide()
at YYYYYY.Boundary.ZzzzzForm.<HideWaitForm>b__c() in R:\Projects\XXXX\trunk\src\YYYYYY\Boundary\ZzzzzForm.cs:line 514
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
遺憾的截圖,我想表現的全貌
如果你想等待調用完成,你應該調用同步'Invoke()'。 – SLaks
什麼是堆棧跟蹤? – SLaks
你有兩個UI線程嗎? – SLaks