dim t as system.threading.thead
t=new system.threading.thead(addressof newproess)
t.start()
我点两次button1以后,就会开两个线程!
如何在我点以前终止以前的线程??
我用t.about没有用牙!
...全文
295打赏收藏
关于线程的结束!
关于线程的结束! 我创建线程以后,如何结束? 例如 button1里面: dim t as system.threading.thead t=new system.threading.thead(addressof newproess) t.start() 我点两次button1以后,就会开两个线程! 如何在我点以前终止以前的线程?? 我用t.about没有用牙!
你用的是以前版本的vb,正式版修正了这个bug.
即使是你现在的版本,也有一个解决办法(在正式版中也通用)
例:
Imports System
Imports System.Windows.Forms
Imports System.Threading
Class ThreadExample
' The method that will be called when the thread is started.
Sub MyThreadProc()
Dim i As Integer
i = 1
Try
For i = 1 To 30000
Console.WriteLine("ThreadExample MyThreadProc is running on another thread")
Next i
Catch e As ThreadAbortException
Console.WriteLine("要死")
End Try
End Sub
End Class
Module Module1
Sub Main()
Console.WriteLine("Thread Simple Sample")
Dim oThreadExample As New ThreadExample()
' Create a ThreadStart object, passing the address of oThreadExample.MyThreadProc.
' Note that Visual Basic is using syntactic sugar here. The constructor
' for ThreadStart actually takes two parameters: an object
' and the address of the method body.
Dim otter As New ThreadStart(AddressOf oThreadExample.MyThreadProc)
' Create a Thread object.
Dim oThread As New Thread(otter)
' Starting the thread invokes the ThreadStart delegate.
oThread.Start()
oThread.Abort()
Console.ReadLine()