My preferred solution for this is to create a class that holds all the data
that the thread will need. Then, make an instance (non-static) method in
that class to encapsulate whatever work it is that you want to do in the
thread. Create an instance of your class in your main thread, initialize it
however you like, and then call Thread.Start on the method:
using System.Threading;
namespace ThreadExample {
class ThreadExample {
static void Main() {
myClass C = new myClass(12, "hello"); // construct and
initialize object to hold data for the thread
workerThread = new Thread(new
ThreadStart(c.myThreadStartMethod));
workerThread.IsBackground = true;
workerThread.Start();
}
}
class myClass {
private int SomeField;
private string SomeOtherField;
public void myClass(int i, string s) {
SomeField = i;
SomeOtherField = s;
}
public void myThreadStartMethod() {
// do lots of work involving SomeField and SomeOtherField
}
}
}