本文整理匯總了VB.NET中System.Threading.Thread.Abort方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Thread.Abort方法的具體用法?VB.NET Thread.Abort怎麽用?VB.NET Thread.Abort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Threading.Thread
的用法示例。
在下文中一共展示了Thread.Abort方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Test
' 導入命名空間
Imports System.Threading
Public Class Test
<MTAThread> _
Shared Sub Main()
Dim newThread As New Thread(AddressOf TestMethod)
newThread.Start()
Thread.Sleep(1000)
' Abort newThread.
Console.WriteLine("Main aborting new thread.")
newThread.Abort("Information from Main.")
' Wait for the thread to terminate.
newThread.Join()
Console.WriteLine("New thread terminated - Main exiting.")
End Sub
Shared Sub TestMethod()
Try
While True
Console.WriteLine("New thread running.")
Thread.Sleep(1000)
End While
Catch abortException As ThreadAbortException
Console.WriteLine( _
CType(abortException.ExceptionState, String))
End Try
End Sub
End Class
示例2: Thread.Abort()
' 導入命名空間
Imports System
Imports System.Drawing
Imports System.Threading
Imports System.Windows.Forms
Imports System.IO
public class MainClass
Shared Sub Main()
Dim Thrd As Thread
Dim TStart As New ThreadStart(AddressOf BusyThread)
Thrd = New Thread(TStart)
Thrd.Priority = ThreadPriority.Highest
Thrd.Start()
Console.WriteLine(Thrd.ThreadState.ToString("G"))
Console.WriteLine("Thrd.IsAlive " & Thrd.IsAlive)
If Thrd.IsAlive Then
Thrd.Abort()
Thrd.Join()
End If
End Sub
Shared Sub BusyThread()
While True
'Console.Write("thread ")
End While
End Sub
End Class