2

これは通常の「Corss-Thread 操作」BS ではないため、明白な解決策を投稿しないでください。

これは、何日もの間私を夢中にさせてきたものです。

私はNotifyIconバインドされたを持っていますContextMenuStrip。すべてが正常に機能しますが、クロススレッド例外が発生することがあります (これを再現するための正確な手順を思い出せません)。ContextMenuStrip/へのすべてのアクセスNotifyIconは Invoke cr*p で埋められますが、それでも - ユーザーが通知アイコンを右クリックすると - 例外が発生します。

これは、例外からの完全なデータです。

Message: クロススレッド操作が無効です: コントロール '' は、それが作成されたスレッド以外のスレッドからアクセスされました。

Call stack:

System.Windows.Forms.Control.get_Handle() で

System.Windows.Forms.Control.SetBoundsCore (Int32 x、Int32 y、Int32 幅、Int32 高さ、BoundsSpecified 指定) で

System.Windows.Forms.ToolStrip.SetBoundsCore (Int32 x、Int32 y、Int32 幅、Int32 高さ、BoundsSpecified 指定) で

System.Windows.Forms.ToolStripDropDown.SetBoundsCore (Int32 x、Int32 y、Int32 幅、Int32 高さ、BoundsSpecified 指定) で

System.Windows.Forms.Control.SetBounds (Int32 x、Int32 y、Int32 幅、Int32 高さ、BoundsSpecified 指定) で

System.Windows.Forms.Control.set_Location (ポイント値) で

System.Windows.Forms.ToolStripDropDown.Show (Int32 x、Int32 y) で

System.Windows.Forms.ContextMenuStrip.ShowInTaskbar (Int32 x、Int32 y) で

System.Windows.Forms.NotifyIcon.ShowContextMenu() で

System.Windows.Forms.NotifyIcon.WndProc (メッセージ & メッセージ) で

System.Windows.Forms.NotifyIcon.NotifyIconNativeWindow.WndProc (メッセージ & m) で

System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd、Int32 msg、IntPtr wparam、IntPtr lparam) で

System.Windows.Forms.UnsafeNativeMethods.PeekMessage (MSG& msg、HandleRef hwnd、Int32 msgMin、Int32 msgMax、Int32 削除) で

System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Int32 dwComponentID、Int32 理由、Int32 pvLoopData) で

System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 理由、ApplicationContext コンテキスト) で

System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 理由、ApplicationContext コンテキスト) で

System.Windows.Forms.Application.Run (フォーム mainForm) で

StarLIMS.Grabber.Manager.Program.Main(String[] args) in D:\SDMS14SP2\StarLIMS.Grabber\StarLIMS.Grabber.Manager\Program.cs:line 34

System.AppDomain._nExecuteAssembly (アセンブリ アセンブリ、文字列 [] 引数) で

System.AppDomain.ExecuteAssembly (文字列 assemblyFile、証拠 assemblySecurity、文字列 [] 引数) で

Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() で

System.Threading.ThreadHelper.ThreadStart_Context (オブジェクトの状態) で

System.Threading.ExecutionContext.Run (ExecutionContext executionContext、ContextCallback コールバック、オブジェクト状態) で System.Threading.ThreadHelper.ThreadStart() で

4

1 に答える 1

0

Doggettが指摘したように、私ContextMenuStripはctorではなくOnLoadで初期化されました... ctorに移動すると、問題はなくなりました。

于 2010-12-05T11:12:46.250 に答える