﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » invalid thread after an InfoBox with contextMenu</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Wed, 17 Jun 2026 08:47:26 GMT</lastBuildDate><ttl>20</ttl><item><title>invalid thread after an InfoBox with contextMenu</title><link>http://forum.strataframe.net/FindPost10870.aspx</link><description>Hi,&lt;P&gt;under certain condition, the main menu in my MDI form may call an infobox with a contextmenu .&lt;BR&gt;[codesnippet]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; lnReccount &amp;gt; 5000 &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;With&lt;/FONT&gt;&lt;FONT size=2&gt; InfoBox.NotifyBoxSettings&lt;/P&gt;&lt;P&gt;.CardinalPosition = MessagingCardinalPosition.NorthWest&lt;/P&gt;&lt;P&gt;.SpecialEffect = InfoBoxSpecialEffect.Fade&lt;/P&gt;&lt;P&gt;.Opacity = 80&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;With&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;InfoBox.NotifyBox(lcTitre, lcMessage, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.ThemedContextMenuStripInfoBox, MessagingCardinalPosition.NorthWest)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;P&gt;Here's the code for one item&lt;BR&gt;[codesnippet]&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; CuvesToolStripMenuItem_Click(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; sender &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; System.Object, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; e &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; System.EventArgs) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Handles&lt;/FONT&gt;&lt;FONT size=2&gt; CuvesToolStripMenuItem.Click, showCuvesTrue.Click&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; frmCuves &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt; formcuves&lt;/P&gt;&lt;P&gt;frmCuves.MdiParent = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;frmCuves.Show()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;P&gt;And of course, I get an error because I'm not on the required thread:&lt;BR&gt;[quote]InvalidOperationException&lt;BR&gt;&amp;nbsp; Opération inter-threads non valide&amp;nbsp;: 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éé.&lt;/P&gt;&lt;P&gt;Source&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : System.Windows.Forms&lt;/P&gt;&lt;P&gt;Stack Trace: &lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Control.get_Handle()&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Control.get_CreateThreadId()&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Form.set_MdiParentInternal(Form value)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Form.set_MdiParent(Form value)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à 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&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Control.WmMouseUp(Message&amp;amp; m, MouseButtons button, Int32 clicks)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Control.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ScrollableControl.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStrip.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.ToolStripDropDown.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Control.ControlNative&amp;#119;indow.OnMessage(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Control.ControlNative&amp;#119;indow.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Native&amp;#119;indow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;amp; msg)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Form.ShowDialog(IWin32Window owner)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Windows.Forms.Form.ShowDialog()&lt;BR&gt;&amp;nbsp;&amp;nbsp; à MicroFour.StrataFrame.Messaging.InfoBox.NewAlertBoxThread()&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Threading.ThreadHelper.ThreadStart_Context(Object state)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)&lt;BR&gt;&amp;nbsp;&amp;nbsp; à System.Threading.ThreadHelper.ThreadStart()&lt;BR&gt;[/quote]&lt;P&gt;How to ensure I'm in the "main" thread?&lt;P&gt;Thanks</description><pubDate>Thu, 16 Aug 2007 11:10:14 GMT</pubDate><dc:creator>Michel Levy</dc:creator></item><item><title>RE: invalid thread after an InfoBox with contextMenu</title><link>http://forum.strataframe.net/FindPost10895.aspx</link><description>LOL...yeah, we all do it from time to time :)&amp;nbsp; 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.&amp;nbsp; :)</description><pubDate>Thu, 16 Aug 2007 11:10:14 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: invalid thread after an InfoBox with contextMenu</title><link>http://forum.strataframe.net/FindPost10888.aspx</link><description>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).&lt;BR&gt;The problem is still here with CheckForIllegallCrossThreads turned to False.&lt;P&gt;So I'll wait for a real solution you'd provide later :) and modify my UI&lt;BR&gt;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 :doze:&lt;P&gt;Thanks</description><pubDate>Thu, 16 Aug 2007 02:58:25 GMT</pubDate><dc:creator>Michel Levy</dc:creator></item><item><title>RE: invalid thread after an InfoBox with contextMenu</title><link>http://forum.strataframe.net/FindPost10878.aspx</link><description>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.&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; The most simple ting to do, which is do not recommend, is to turn off cross-thread checking.&amp;nbsp; You can do this just to see if your problem goes away.&amp;nbsp; Then you can work on a more appropriate solution.&lt;/P&gt;&lt;P&gt;[codesnippet]System.WIndows.Forms.Form.CheckForIllegalCrossThreads = False[/codesnippet]&lt;/P&gt;&lt;P&gt;The call needs to be be Invoked on the same thread from which it was created.&amp;nbsp; 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.&amp;nbsp; 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.&lt;/P&gt;&lt;P&gt;Rather than getting too deep at first, turn off the property mentioned above to see if your problem goes away.&amp;nbsp; :)</description><pubDate>Wed, 15 Aug 2007 14:27:06 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>