Spawning a thread

Name spaces to be used are

System.Threading


Imports System.Threading
Class workerclass
Public Sub dosomework()
Console.WriteLine("secondary thread:")
Dim i As Integer
For i = 0 To 10

Console.WriteLine(i & ",")


Next
Console.WriteLine()
End Sub
End Class
Module Module1

Sub Main()
Console.WriteLine("primary thread..")
Dim w As workerclass = New workerclass()
Dim backgroundthread As Thread = New Thread(AddressOf w.dosomework)
backgroundthread.Start()



End Sub

End Module




Explanation:
The snippet creates a worker class with dosomework method. Create an object for class.
Create thread object as delegate by passing address of method name.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: