Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
LOL...yeah, we all do it from time to time Events, delegates, and threads are awesome tools, but it takes a few problems like you ran into for everything to kind of start coming together in most cases.
|
Group: StrataFrame Users
Posts: 193,
Visits: 9K
|
I understand that it's a complex question... that I don't understand because I'm not a .NET developer (my real job is data development). The problem is still here with CheckForIllegallCrossThreads turned to False. So I'll wait for a real solution you'd provide later and modify my UI BTW, it was not really a good UI : using an infobox and its contextmenu as a subitem of a main menu is not a good practice Thanks
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
This is a relatively complex question and we actually cover a segment over this type of thing in class because many developers run into this type of thing when threads start coming into the forumla. You are running into a Cross-Thread violation and this is related to .NET and communicated with any type of UI object that has been created another thread. The most simple ting to do, which is do not recommend, is to turn off cross-thread checking. You can do this just to see if your problem goes away. Then you can work on a more appropriate solution. System.WIndows.Forms.Form.CheckForIllegalCrossThreads = False The call needs to be be Invoked on the same thread from which it was created. This is why we implement the ISynchronizeInvoke interface on many of our controls so that we can raise events on the thread from which the control was created. If you'll notice, any object that inherits Control has an intrinsic method called Invoke() which allows a delegate to be passed over and the call made on the base thread. Rather than getting too deep at first, turn off the property mentioned above to see if your problem goes away.
|
Group: StrataFrame Users
Posts: 193,
Visits: 9K
|
Hi, under certain condition, the main menu in my MDI form may call an infobox with a contextmenu .
If lnReccount > 5000 ThenWith InfoBox.NotifyBoxSettings.CardinalPosition = MessagingCardinalPosition.NorthWest .SpecialEffect = InfoBoxSpecialEffect.Fade .Opacity = 80 End WithInfoBox.NotifyBox(lcTitre, lcMessage, Me, Me.ThemedContextMenuStripInfoBox, MessagingCardinalPosition.NorthWest)End If Here's the code for one item
Private Sub CuvesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CuvesToolStripMenuItem.Click, showCuvesTrue.ClickDim frmCuves As New formcuvesfrmCuves.MdiParent = MefrmCuves.Show() End Sub And of course, I get an error because I'm not on the required thread:
InvalidOperationException Opération inter-threads non valide : le contrôle 'Ecran' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé. Source : System.Windows.Forms Stack Trace: à System.Windows.Forms.Control.get_Handle() à System.Windows.Forms.Control.get_CreateThreadId() à System.Windows.Forms.Form.set_MdiParentInternal(Form value) à System.Windows.Forms.Form.set_MdiParent(Form value) à bcuvtest1.Ecran.CuvesToolStripMenuItem_Click(Object sender, EventArgs e) dans C:\Documents and Settings\MICHEL\Mes documents\Visual Studio 2005\Projects\bcuvtest1\bcuvtest1\Ecran.vb:ligne 77 à System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) à System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) à System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) à System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) à System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) à System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) à System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) à System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) à System.Windows.Forms.Control.WndProc(Message& m) à System.Windows.Forms.ScrollableControl.WndProc(Message& m) à System.Windows.Forms.ToolStrip.WndProc(Message& m) à System.Windows.Forms.ToolStripDropDown.WndProc(Message& m) à System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m) à System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m) à System.Windows.Forms.Nativewindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) à System.Windows.Forms.Form.ShowDialog(IWin32Window owner) à System.Windows.Forms.Form.ShowDialog() à MicroFour.StrataFrame.Messaging.InfoBox.NewAlertBoxThread() à System.Threading.ThreadHelper.ThreadStart_Context(Object state) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) à System.Threading.ThreadHelper.ThreadStart()
How to ensure I'm in the "main" thread? Thanks
|