VB.NET事件在深处处理



任何人确实知道事件在vb.net中的工作方式我特别怀疑,如果事件代码未完成处理事件并发生新的事件发生会发生什么。

即:我有DoubleClick事件,用户反复且持久双击非常快。

事件代码以相同形式(而非多线程)调用一些子例程和功能

事件代码重新启动表格或等待直到完成并在执行所有代码时重新输入?

今天我发现以下两个错误

错误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)

错误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)

这个错误并非总是如此,我有大约20台机器具有相同的程序,只有一个用户有这个问题,当他重复快速单击时,它总是发生。


我正在使用以下代码删除抽头

Dim CurrentTab As TabPage = AlarmsTabControl.SelectedTab
AlarmsTabControl.TabPages.Remove(CurrentTab)

winform框架是单线程。因此,所有事件均在单线程上处理。因此,当调用事件处理程序时,直到第一个完成的事件处理程序都不会被调用。换句话说,事件处理程序以串行方式调用。

事件处理程序可以被另一个事件中断的唯一方法是,它是否通过调用Application.DoEvents积极放弃控制。您可以想象,调用DoEvents可能会导致意外行为。由于调用DoEvents通常会导致错误,因此它被广泛灰心并放置为设计不良的标志。在这种情况下,通常表明使用BackgroundWorker更合适。

更深层次

从操作系统接收窗口消息时,

与UI相关的事件会触发。传入的窗口消息将添加到队列中。每个过程的责任是从队列中读取这些窗口消息并适当处理它们。通常,这是在消息循环中完成的,该消息循环会按顺序处理队列中的每个消息,或者iDLE,直到收到新消息为止。每当消息循环找到要处理的新消息时,都会调用一个窗口过程。窗口过程通常称为WindowProcWndProc。在.NET WINFORM项目中,消息循环是通过调用Application.Run

来启动的。

最新更新