Reputation: 1151
anybody does know how events works in VB.NET My specifically doubt is What happen if the event code doesn't finish of handle the event and a new one happen.
I.E.: I have doubleClick event and the user make repeatedly and insistently double click a lot of times very fast.
The event code calls some sub routines and functions in the same form(not multi threading)
The event code Restart form the top or wait until finish and re enter when all the code was executed?
Today I catch the following two errors
Error 1:
Error al crear identificador de ventana.
en System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
en System.Windows.Forms.Control.CreateHandle()
en System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
en System.Windows.Forms.Control.CreateControl()
en System.Windows.Forms.Control.ControlCollection.Add(Control value)
en System.Windows.Forms.TabControl.ControlCollection.Add(Control value)
en System.Windows.Forms.TabControl.TabPageCollection.Insert(Int32 index, TabPage tabPage)
en Commands.Form1.DataGridViewAlarms_CellMouseDoubleClick(Object sender, DataGridViewCellMouseEventArgs e)
Error 2:
Error al crear identificador de ventana.
en System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
en System.Windows.Forms.Control.CreateHandle()
en System.Windows.Forms.Control.get_Handle()
en System.Windows.Forms.Control.CreateGraphicsInternal()
en System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
en System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
en System.Windows.Forms.Control.WndProcException(Exception e)
en System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e)
en System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
en System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
en System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
en System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
en System.Windows.Forms.Control.CreateHandle()
en System.Windows.Forms.TabControl.CreateHandle()
en System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
en System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
en System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
en System.Windows.Forms.Control.CreateControl()
en System.Windows.Forms.Control.ControlCollection.Add(Control value)
en System.Windows.Forms.TabControl.ControlCollection.Add(Control value)
en System.Windows.Forms.TabControl.TabPageCollection.Insert(Int32 index, TabPage tabPage)
en Commands.Form1.DataGridViewAlarms_CellMouseDoubleClick(Object sender, DataGridViewCellMouseEventArgs e)
This errors doesn't happen always I have about 20 machines with the same program and just one user have this problems and it always happen when he double click repeatedly fast.
I'm Removing the TapPages with the following Code
Dim CurrentTab As TabPage = AlarmsTabControl.SelectedTab
AlarmsTabControl.TabPages.Remove(CurrentTab)
Upvotes: 2
Views: 925
Reputation: 43743
The WinForm framework is single-threaded. As such, all events are processed on a single-thread. Therefore, when an event handler is called, no other event handlers will be called until the first one has completed. In other words, the event handlers are called in a serial fashion.
The only way that an event handler can be interrupted by another event is if it actively relinquishes control by calling Application.DoEvents
. As you can imagine, calling DoEvents
can cause unexpected behavior. Since calling DoEvents
typically leads to bugs, it is widely discouraged and panned as a sign of poor design. In such cases, it is usually a sign that using a BackgroundWorker
is more appropriate.
UI-related events are triggered when window messages are received from the operating system. Incoming window messages are added to a queue. It is the responsibility of each process to read those window messages from the queue and handle them appropriately. Typically this is done in a Message Loop which processes each message in the queue in order, or idles until a new message is received. Each time the message loop finds a new message to be processed, it calls a Window Procedure. The window procedure is typically called WindowProc
or WndProc
. In .NET WinForm projects, the message loop is initiated by calling Application.Run
.
Upvotes: 3