Can you explain in brief how can we implement threading ?

Q

.NET INTERVIEW QUESTIONS - Can you explain in brief how can we implement threading ?

✍: Guest

A

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pthread1 As New Thread(AddressOf Thread1)
Dim pthread2 As New Thread(AddressOf Thread2)
pthread1.Start()
pthread2.Start()
End Sub
Public Sub Thread1()
Dim pintcount As Integer
Dim pstr As String
pstr = “This is first thread”
Do Until pintcount > 5
lstThreadDisplay.Items.Add(pstr)
pintcount = pintcount + 1
Loop
End Sub
Public Sub Thread2()
Dim pintcount As Integer
Dim pstr As String
pstr = “This is second thread”
Do Until pintcount > 5
lstThreadDisplay.Items.Add(pstr)
pintcount = pintcount + 1
Loop
End Sub

Above is a sample code which shows simple sample code for threading. Above sample has two methods “Thread1()” and “Thread2()” which are started in multi-threaded mode in Form load event of the sample.

2009-11-17, 4401👍, 0💬