目前做法,非UI线程进行数据计算,计算的数据显示到UI线程上,
问题:非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)