Create a new thread in VB.NET
multithreading, vb.net
Solution
There's two ways to do this;
With the `AddressOf` operator to an existing method
Sub MyBackgroundThread()
Console.WriteLine("Hullo")
End Sub
And then create and start the thread with;
Dim thread As New Thread(AddressOf MyBackgroundThread)
thread.Start()
Or as a lambda function.
Dim thread as New Thread(
Sub()
Console.WriteLine("Hullo")
End Sub
)
thread.Start()
Problem
I am trying to create a new thread using an anonymous function but I keep getting errors. Here is my code: ``` New Thread(Function() 'Do something here End Function).Start ``` Here are the errors I get: New: Syntax Error End Function: 'End Function' must be preceded by a matching 'Function'.