Dies ist kein regulärer 'Corss-Thread Opeartion' BS, also veröffentlichen Sie bitte keine offensichtlichen Lösungen.Lassen Sie den 'Cross-thread operation not valid' beim Versuch, den Menustrip eines Notificon zu zeigen
Das ist etwas, das mich seit Tagen verrückt macht.
Ich habe eine NotifyIcon
, mit einem gebundenen ContextMenuStrip
. Alles funktioniert so, wie es sollte, aber manchmal (und ich kann mich nicht erinnern, die genauen Schritte, um dies zu reproduzieren) bekomme ich die Cross-Thread-Ausnahme. All mein Zugriff auf die ContextMenuStrip
/NotifyIcon
ist mit dem Invoke cr * p aufgefüllt, aber immer noch - wenn der Benutzer mit der rechten Maustaste auf das Benachrichtigungssymbol klickt - wird die Ausnahme ausgelöst.
Dies ist die vollständigen Daten aus der Ausnahme:
Message
: Cross-Thread-Betrieb nicht gültig: Control ‚‘ zugegriffen von einem anderen Thread als der Thread es erstellt wurde.
Call stack
:
bei System.Windows.Forms.Control.get_Handle()
bei System.Windows.Forms.Control.SetBoundsCore (Int32 x, y Int32, Breite Int32, Int32 Höhe, angegeben BoundsSpecified)
bei System.Windows.Forms.ToolStrip.SetBoundsCore (Int32 x, y Int32, Int32 Breite, Höhe Int32, BoundsSpecified angegeben)
bei System.Windows.Forms.ToolStripDropDown.SetBoundsCore (Int32 x, y Int32, Int32 Breite, Höhe Int32, BoundsSpecified angegeben)
bei System.Windows.Forms.Control.SetBounds (Int32 x, y Int32, Int32 Breite , Int32 Höhe, angegeben BoundsSpecified)
bei System.Windows.Forms.Control.set_Location (Punktwert)
bei System.Windows.Forms.ToolStripDropDown.Show (Int32 x, y Int32)
bei System.Windows.Forms.ContextMenuStrip.ShowInTaskbar (Int32 x, Int32 y)
bei System.Windows.Forms.NotifyIcon.ShowContextMenu()
bei System.Windows.Forms.NotifyIcon.WndProc (Message & msg)
bei System.Windows.Forms.NotifyIcon.NotifyIconNativeWindow.WndProc (Message & m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.PeekMessage (MSG & msg, HandleRef HWND, Int32 msgMin, Int32 msgmax, Int32 entfernen)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (Int32 DwComponentID, Int32 Grund Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 Grund Application Kontext)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 Grund Application Kontext)
bei System.Windows.Forms. Application.Run (Form Mainform)
bei StarLIMS.Grabber.Manager.Program.Main (String [] args) in D: \ SDMS14SP2 \ StarLIMS.Grabber \ StarLIMS.Grabber.Manager \ Program.cs: Leitung 34
bei System.AppDomain._nExecuteAssembly (Assembly Assembly, String [] args)
bei System.AppDomain.ExecuteAssembly (String assembly, Evidence assemblySecurity, String [] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context (Objektzustand)
bei System.Threading.ExecutionContext.Run (ExecutionContext ExecutionContext, Context Rückruf, Objektzustand) bei System.Threading.ThreadHelper.ThreadStart()
Beachten Sie, dass die Ausnahmebedingungsnachricht die genaue Nachricht ist, die ich bekomme, der Wert innerhalb der '' ist leer – Nissim
Ist es möglich, dass die NotifyIcon in einem anderen Thread als dem Hauptthread erstellt wird? – Doggett
können Sie bitte die ** Invoke cr * p ** posten Zugriff auf die 'ContextMenuStrip/NotifyIcon'? –