Thread.Start begins a dedicated .NET thread after its Thread object has been created and optionally configured. The parameterless overload invokes a delegate without arguments; the object overload passes a value to a parameterized delegate, allowing similar threads to receive different inputs. section 4.1.1
Listing 4.1 Creating a thread
public void RunInBackground()
{
var newThread = new Thread(CodeToRunInBackgroundThread); #1
newThread.IsBackground = true; #2
newThread.Start(); #3
}
private void CodeToRunInBackgroundThread() #4
{
Console.WriteLine("Do stuff");
}
Creates a Thread, marks it as a background thread, and starts its callback. section 4.1.1
Passing work-specific data
Create a Thread with a parameterized callback and call Start(i) inside a loop. Each callback receives its loop index through an object parameter. section 4.1.1
Use Thread.Start with these practical constraints:
- Configure the Thread before starting it; background status is optional. section 4.1.1
- Match delegate and Start overloads deliberately; mismatches are supported, but a missing argument becomes null for a parameterized delegate. section 4.1.1
- Use Join when the initiating code must wait for started threads to finish. section 4.7
