Posted by: Sourav | October 3, 2016

isalive and join in threading ,Visual Basic Teacher Sourav,Kolkata 09748184075


Option Strict On
Option Explicit On

Imports System
Imports System.Threading

Module Module1

Sub Main()
Console.WriteLine(“Main started”)
Dim t1 As Thread = New Thread(AddressOf thread1function)
t1.Start()

Dim t2 As Thread = New Thread(AddressOf thread2function)
t2.Start()
‘t1.Join()
If t1.Join(1000) Then

Console.WriteLine(“Thread1 function completed”)
Else

Console.WriteLine(“Thread1 function not completed in 1 second”)
End If
t2.Join()
Console.WriteLine(“Thread2 function completed”)
Dim i As Integer
For i = 1 To 10

If t1.IsAlive Then
Console.WriteLine(“The Thread1 Function is still doing it’s work”)
Thread.Sleep(500)

Else
Console.WriteLine(“Thread1 function completed”)
End If
Next
Console.WriteLine(“Main Completed”)

Console.ReadLine()

End Sub

Public Sub thread1function()
Console.WriteLine(“Thread1 function started”)
Thread.Sleep(5000)
Console.WriteLine(“Thread1 function about to be returned”)
End Sub
Public Sub thread2function()
Console.WriteLine(“Thread2 function started”)
End Sub
End Module

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: