C
Carl Heller
If I'm creating a class to do some work that I want threaded out, where's
the best location to call ThreadStart? Or does it depend on the nature of
the work?
a. Call it outside the class, giving it the starting method of the class?
b. Have the class create the thread itself?
ie:
x = new WorkerClass();
ioThread = new Thread(new ThreadStart(x.StartWork));
ioThread.Start();
...
Class WorkerClass
{
...
public void StartWork()
{
SomeMethod();
}
}
or
x = new WorkerClass();
x.StartWork();
...
Class WorkerClass
{
private Thread WorkerThread;
...
public void StartWork()
{
WorkerThread = new Thread(new ThreadStart(this.SomeMethod));
WorkerThread.Start();
}
}
the best location to call ThreadStart? Or does it depend on the nature of
the work?
a. Call it outside the class, giving it the starting method of the class?
b. Have the class create the thread itself?
ie:
x = new WorkerClass();
ioThread = new Thread(new ThreadStart(x.StartWork));
ioThread.Start();
...
Class WorkerClass
{
...
public void StartWork()
{
SomeMethod();
}
}
or
x = new WorkerClass();
x.StartWork();
...
Class WorkerClass
{
private Thread WorkerThread;
...
public void StartWork()
{
WorkerThread = new Thread(new ThreadStart(this.SomeMethod));
WorkerThread.Start();
}
}