多线程应用

lovetsfuer 2014-07-02 05:29:34
winform的程序,界面上有组件,实时数据组成,线程获得数据处理后更新界面上的组件状态,更新界面上实时数据,尝试把实时数据与组件状态更新到多个线程去处理,效果不是很好,有异常如下:
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)
在 Notenamo.NoteThreadUI.SetBorderStyle[TObject](TObject objCtrl, BorderStyle style, Dynamo winf)
在 NoteNynamo.Nynamo.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)

如果数据处理与组件状态更新一个线程运行状态稳定,速度上就更不上了,不知有啥好的办法不?
...全文
165 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
落叶1210 2014-07-03
  • 打赏
  • 举报
回复
我怀疑你的问题是,组件对象尚未创建完毕,另一个线程试图访问造成的。 多线程肯定是没问题的,是你代码控制的问题。
lovetsfuer 2014-07-03
  • 打赏
  • 举报
回复
引用 2 楼 caozhy 的回复:
你有没有通过Convert.Invoke去更新界面?
更新界面了
引用 3 楼 luoye4321 的回复:
我怀疑你的问题是,组件对象尚未创建完毕,另一个线程试图访问造成的。 多线程肯定是没问题的,是你代码控制的问题。
有可能,有啥合理的方法判断组件创建结束? 线程内多个执行的方法,优先级执行?
threenewbee 2014-07-02
  • 打赏
  • 举报
回复
你有没有通过Convert.Invoke去更新界面?

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧