非UI现场数据计算更新UI线程
目前做法,非UI线程进行数据计算,计算的数据显示到UI线程上,
问题:非UI线程thread2整个运行一圈需要55~63秒
如果把thread2线程内计算方法分出来一部分,多个非UI线程对一个UI线程,就会报异常,我的理解是多个对UI线程进行操作照成的异常?有没有合理的方法?
System.OutOfMemoryException: 引发类型为“System.OutOfMemoryException”的异常。
在 System.Windows.Forms.UnsafeNativeMethods.SetWindowLongPtr32(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
在 System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
在 System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean assignUniqueID)
在 System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle)
在 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 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)
在 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)
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Control.RecreateHandleCore()
在 System.Windows.Forms.PictureBox.set_BorderStyle(BorderStyle value)
在 BoteDynamo.BoteThreadUI.SetBorderStyle[TObject](TObject objCtrl, BorderStyle style, Dynamo winf)
在 BoteDynamo.Dynamo.pic_MouseLeave(Object sender, EventArgs e)
在 System.Windows.Forms.Control.OnMouseLeave(EventArgs e)
在 System.Windows.Forms.Control.WmMouseLeave(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
System.OutOfMemoryException: 引发类型为“System.OutOfMemoryException”的异常。
在 System.Windows.Forms.UnsafeNativeMethods.SetWindowLongPtr32(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
在 System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
在 System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean assignUniqueID)
在 System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle)
在 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 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)
在 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)
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Control.RecreateHandleCore()
在 System.Windows.Forms.PictureBox.set_BorderStyle(BorderStyle value)
在 ThreadUI.SetBorderStyle[TObject](TObject objCtrl, BorderStyle style, Dynamo winf)
在 Dynamo.pic_MouseLeave(Object sender, EventArgs e)
在 System.Windows.Forms.Control.OnMouseLeave(EventArgs e)
在 System.Windows.Forms.Control.WmMouseLeave(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
问题:非UI线程thread2整个运行一圈需要55~63秒
//线程
thread2 = new Thread(new ThreadStart(UpdateForm));
thread2.IsBackground = true;
thread2.Start();
//线程方法
public void UpdateForm()
{
while (tj2)
{
...
if (mycom1.IsOpen)
{
.....
MyClass.ThreadUI.SetTxt(TXTValue1, "-" + num.ToString(), this);
}
....
}
}
如果把thread2线程内计算方法分出来一部分,多个非UI线程对一个UI线程,就会报异常,我的理解是多个对UI线程进行操作照成的异常?有没有合理的方法?
System.OutOfMemoryException: 引发类型为“System.OutOfMemoryException”的异常。
在 System.Windows.Forms.UnsafeNativeMethods.SetWindowLongPtr32(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
在 System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
在 System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean assignUniqueID)
在 System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle)
在 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 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)
在 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)
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Control.RecreateHandleCore()
在 System.Windows.Forms.PictureBox.set_BorderStyle(BorderStyle value)
在 BoteDynamo.BoteThreadUI.SetBorderStyle[TObject](TObject objCtrl, BorderStyle style, Dynamo winf)
在 BoteDynamo.Dynamo.pic_MouseLeave(Object sender, EventArgs e)
在 System.Windows.Forms.Control.OnMouseLeave(EventArgs e)
在 System.Windows.Forms.Control.WmMouseLeave(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
System.OutOfMemoryException: 引发类型为“System.OutOfMemoryException”的异常。
在 System.Windows.Forms.UnsafeNativeMethods.SetWindowLongPtr32(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
在 System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(HandleRef hWnd, Int32 nIndex, WndProc wndproc)
在 System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean assignUniqueID)
在 System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle)
在 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 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)
在 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)
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Control.RecreateHandleCore()
在 System.Windows.Forms.PictureBox.set_BorderStyle(BorderStyle value)
在 ThreadUI.SetBorderStyle[TObject](TObject objCtrl, BorderStyle style, Dynamo winf)
在 Dynamo.pic_MouseLeave(Object sender, EventArgs e)
在 System.Windows.Forms.Control.OnMouseLeave(EventArgs e)
在 System.Windows.Forms.Control.WmMouseLeave(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
...全文
相关推荐
qt编程_在子线程中更新UI界面
qt编程_在子线程中更新UI界面
Qt多线程实战:从UI卡顿定位到跨线程通信与性能优化
桌面应用开发中,界面卡顿是常见的工程痛点,根源往往在于主线程承担了过多耗时任务。理解Qt事件循环与线程模型,是解决此类问题的基础。通过QThread、QtConcurrent与线程池的合理选型,可以将串口采集、FFT频域计算等任务移出UI线程,并借助信号槽队列连接实现安全的跨线程通信。掌握线程销毁时机与任务收尾策略,能够有效避免崩溃和资源泄漏。典型场景如基于QCustomPlot的实时频谱仪,通过异步数据流水线设计,既能保证界面流畅刷新,又能提升整体吞吐。本文从量化阻塞出发,梳理Qt多线程的实用模式与性能调
Xamarin.Android 非UI线程更新UI
Xamarin.Android 非UI线程更新UI
WPF 使用线程更新UI
WPF 使用线程更新绑定数据的UI控件值,从而使得界面不卡顿。
MFC用户界面线程的创建示例
MFC用户界面线程的创建示例,该实例演示了文件复制的自定义,并实时显示操作进度、操作时间等,采用工作线程和用户界面线程想结合,消息的传递等。



