Thread.Suspend : Thread « System.Threading « VB.Net by API






Thread.Suspend

  


Imports System.Threading

Module Module1

    Public A As Thread = New Thread(AddressOf MethodA)
    Public B As Thread = New Thread(AddressOf MethodB)
    Public C As Thread = New Thread(AddressOf MethodC)

    Sub MethodA()
        Dim I As Integer
        Try
            A.Suspend()
            For I = 0 To 250
                Console.Write("A")
            Next
        Catch E As ThreadStateException
            Console.WriteLine("Thread A Expection" & E.ToString())
        End Try

    End Sub

    Sub MethodB()
        Dim I As Integer
        Try
            For I = 0 To 250
                Console.Write("B")
            Next
        Catch E As ThreadAbortException
            Console.Write("Thread B has been aborted")
        End Try

    End Sub

    Sub MethodC()
        Dim I As Integer

        Try
            If (B.IsAlive) Then
                B.Abort()
            End If

            For I = 0 To 250
                If (A.ThreadState = ThreadState.Suspended) Then
                    A.Resume()
                End If

                Console.Write("C")
            Next
        Catch E As Threading.ThreadStateException
            Console.WriteLine("Thread C Expection" & E.ToString())
        End Try
    End Sub

    Sub Main()
        A.Start()
        B.Start()
        C.Start()
    End Sub

End Module

   
    
  








Related examples in the same category

1.Thread.Abort()
2.Thread.CurrentPrincipal
3.Thread.CurrentThread
4.Thread.IsAlive
5.Thread.Join()
6.Thread.Priority
7.Thread.Resume
8.Thread.Sleep