双线程动态提示框报错,这个怎么解决?

[复制链接]
查看11 | 回复4 | 2021-1-27 05:50:22 | 显示全部楼层 |阅读模式
我写了一个双线程动态提示框的小程序,可是运行的时候报错,我的代码及错误提示,错误信息如下:
我的代码如下:
'运行线程t来加载提示窗口---------------
t=NewThread(AddressOfMe.ts)
t.Start()'开始运行t线程
'--------------------------------------
................
................
这里面是程序代码!!!!!!!!!
................
................
'结束线程t------------------------
t.Abort()
t.Join()
t=Nothing
MessageBox.Show(Me,"已成功导入。","提示!",MessageBoxButtons.OK,MessageBoxIcon.Warning)
ExitSub
'结束线程t------------------------
错误提示框:


错误信息:
有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。
**************异常文本**************
System.Threading.ThreadAbortException:正在中止线程。
在System.Windows.Forms.Internal.IntUnsafeNativeMethods.IntFillRect(HandleRefhdc,RECT&rect,HandleRefhbrush)
在System.Windows.Forms.Internal.WindowsGraphics.FillRectangle(WindowsBrushbrush,Int32x,Int32y,Int32width,Int32height)
在System.Windows.Forms.Internal.WindowsGraphics.FillRectangle(WindowsBrushbrush,Rectanglerect)
在System.Windows.Forms.Control.PaintBackColor(PaintEventArgse,Rectanglerectangle,ColorbackColor)
在System.Windows.Forms.Control.PaintBackground(PaintEventArgse,Rectanglerectangle,ColorbackColor,PointscrollOffset)
在System.Windows.Forms.Control.PaintBackground(PaintEventArgse,Rectanglerectangle)
在System.Windows.Forms.Control.OnPaintBackground(PaintEventArgspevent)
在System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgse,Int16layer,BooleandisposeEventArgs)
在System.Windows.Forms.Control.WmPaint(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(IntPtrhWnd,Int32msg,IntPtrwparam,IntPtrlparam)

**************已加载的程序集**************
mscorlib
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
物资管理信息系统
程序集版本:4.0.1.0
Win32版本:4.0.1.0
基本代码:file:///D:/物资管理信息系统/物资管理信息系统.exe
----------------------------------------
Microsoft.VisualBasic
程序集版本:8.0.0.0
Win32版本:8.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Data
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
mscorlib.resources
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
System.Transactions
程序集版本:2.0.0.0
Win32版本:2.0.50727.4927(NetFXspW7.050727-4900)
基本代码:file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
程序集版本:2.0.0.0
Win32版本:2.0.50727.5420(Win7SP1.050727-5400)
基本代码:file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
System.Windows.Forms.resources
程序集版本:2.0.0.0
Win32版本:2.0.50727.4927(NetFXspW7.050727-4900)
基本代码:file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
**************JIT调试**************
要启用实时(JIT)调试,
该应用程序或计算机的.config文件(machine.config)的system.windows.forms节中必须设置
jitDebugging值。
编译应用程序时还必须启用
调试。
例如:


启用JIT调试后,任何无法处理的异常
都将被发送到在此计算机上注册的JIT调试器,
而不是由此对话框处理。

分 -->
回复

使用道具 举报

千问 | 2021-1-27 05:50:22 | 显示全部楼层
谁帮我看下???
回复

使用道具 举报

千问 | 2021-1-27 05:50:22 | 显示全部楼层
t.Abort()
t.Join()
t=Nothing
只有中间一条语句是需要的。
回复

使用道具 举报

千问 | 2021-1-27 05:50:22 | 显示全部楼层
尽管按照上面的做法可以“不出错”,不过这并不是一个好的线程编程方式。
一个好的线程编程方式是“不阻塞”的!当你的父线程去启动一个子线程之后,它该干什么还是干什么,或者直接结束。它不应该使用join阻塞在那里。
windows上的线程所花费的资源相当大,而且也要抢占cpu时间。所以正确的线程使用方法,是在你的ts中去进行MessageBox.Show动作,也就是线程自己去交互(需要使用control.BeginInvoke将交互操作的代码以委托形式注册给UI线程),而不是在父线程里阻塞。
回复

使用道具 举报

千问 | 2021-1-27 05:50:22 | 显示全部楼层
既然用多线程
当然是希望主线程不卡,
但是你阻塞他,就没必要用线程
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行