Reputation: 11137
Is stopping a thread by acting the "break" command at some point a safe way to stop a thread?
Upvotes: 2
Views: 3147
Reputation: 1437
Do you mean doing something like this?
void SomeMethod()
{
while(true)
{
//do something
if(condition)
break;
}
}
//somewhere else...
Thread t = new Thread(SomeMethod);
t.Start();
If so, then yes, it's a safe way to end the thread.
Upvotes: 3
Reputation: 180788
If you are referring to the Break() method in Parallel.For, it is specifically designed to request a safe abort of the looping iterations.
An example of this technique is described here.
Upvotes: 3
Reputation: 30165
A thread abort, which I think is what you meant, is not a proper technique to use - unless the thread is also separated by an appdomain barrier.
Upvotes: 3