vb.net 2005 线程停止问题
我在vb.net 2005的环境下开发报表程序,程序中用到线程(Thread) 功能,
问题是当我关闭程序前用Thread.Abort()方法停止线程运行,但结果是程序
界面是关闭了,但线程(Thread)没有停止还继续运行出报表 ,
1.我想知道如可才 可以停止线程的运行?
2.当我停止线程后,我如何再重新开始线程(Thread)?
3.当线程用太多内存时如可释放内存?
请高手帮助解决问题,急急 谢谢谢..........
我的分不多呢,各位大老日后一定报答
下面是我的代码:
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False 'allow cross thread calls
exportReportThread = New Thread(AddressOf exportReport) '建一個線程
exportReportThread.Start() '開始一個線程,同時會調用 exportReport方法輸出報表
Sub exportReport()
{
items = reportListBox2.Items.Count '獲出要輸出的報表總數
If items > 0 Then
For index = 0 To items - 1
'这里的代码是输出报表
Next
End If
exportReportThread.Abort() '完成所有報表下載時就關閉程線
System.Windows.Forms.Application.Exit() '===Close application
Catch ex As System.Exception
注意:当输出报表太多时用的内存太大,如何一出错就释放内存?或停止原来线程重新开一个线程?
我式过在这里停止线程不起作用
exportReportThread.Abort()
exportReportThread = New Thread(AddressOf exportReport) '建一個線程
exportReportThread.Start() '開始一個線程,同時會調用 exportReport方法輸出報表
exportReport()
'当输出报表有错误时就继续输出其他报表
End Try