R
Ryan Pedersen
I have a small program that executes a single very long running
background thread today.
The scope of all variables in the method that is running in this
thread today are all local to the method. The method doesn't do
anything outside of its local scope.
My question... can I start up a 2nd (3rd, and 4th and so on) thread
running the same method? Is that safe?
Todays code (abridged edition):
Thread t1 = new Thread(new ThreadStart(DoWork));
t1.Start();
public void DoWork()
{
//... do lots of work here...
}
I would like to change the code to...
Thread t1 = new Thread(new ThreadStart(DoWork));
t1.Start();
Thread t2 = new Thread(new ThreadStart(DoWork));
t2.Start();
public void DoWork()
{
//... do lots of work here...
}
Looking at this I know that it is VERY simple and I would suspect that
it would work but why? Can you explain why this works, if it does?
background thread today.
The scope of all variables in the method that is running in this
thread today are all local to the method. The method doesn't do
anything outside of its local scope.
My question... can I start up a 2nd (3rd, and 4th and so on) thread
running the same method? Is that safe?
Todays code (abridged edition):
Thread t1 = new Thread(new ThreadStart(DoWork));
t1.Start();
public void DoWork()
{
//... do lots of work here...
}
I would like to change the code to...
Thread t1 = new Thread(new ThreadStart(DoWork));
t1.Start();
Thread t2 = new Thread(new ThreadStart(DoWork));
t2.Start();
public void DoWork()
{
//... do lots of work here...
}
Looking at this I know that it is VERY simple and I would suspect that
it would work but why? Can you explain why this works, if it does?