> Why do I need to go through all this work just to stop a simple thread for
> simple testing purposes? It seems like too much over kill...
Um, you don't have to do the work. I've done it all for you - you just
need to cut and paste.
> Why could't I then just use
>
[quoted text clipped - 6 lines]
> to stop? That should do the same thing as the class you use but stop the
> thread.
Yes, you can indeed do that if you want.
> I imagine I do not have to even lock ShouldStop because its not
> critical(thread is only reading and main app is only writing).
It needs to either use a volatile variable or use a lock. Either will
do, but you do need one of them, otherwise there's no guarantee that
the worker thread will "see" the new value written by the main app.
> You know, I know there are better ways.. but I'm not looking for a better
> way but just something that works and is the least amount of work...
I suspect you've taken longer posting this reply than cutting and
pasting my code would have taken.
> remember, this isn't for production but for simple testing and I don't
> really care if its not the best. I do want something that works of course
> and doesn't cause any real problems. (Like Abort throws an exception but I
> really don't care about that because I can ignore it)
I've provided you something that works and doesn't cause problems.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jon Slaughter - 09 Sep 2007 20:23 GMT
>> Why do I need to go through all this work just to stop a simple thread
>> for
[quoted text clipped - 29 lines]
> I suspect you've taken longer posting this reply than cutting and
> pasting my code would have taken.
lol, true. But then I'd have to figure out how to use your code ;) Not that
its a bad thing but I actually have seen your code before.
>> remember, this isn't for production but for simple testing and I don't
>> really care if its not the best. I do want something that works of course
[quoted text clipped - 3 lines]
>
> I've provided you something that works and doesn't cause problems.
Depends on how you define problems.
Thing is, I have code that works just fine for my purposes of testing at
this point and I don't feel like re writing it to use your code if I don't
have to. The issue is not making the threads better but just getting it to
shut down so when I run the app it doesn't hang or cause an exception that
VS ends up bitching about(or makes the OS unstable or something like that).
Later on when I end up having to implement the code in a real app I'll
rewrite it to use ThreadPool... or if your lucky maybe even your code.
Thanks,
Jon
Jon Skeet [C# MVP] - 10 Sep 2007 07:29 GMT
> > I've provided you something that works and doesn't cause problems.
>
[quoted text clipped - 7 lines]
> Later on when I end up having to implement the code in a real app I'll
> rewrite it to use ThreadPool... or if your lucky maybe even your code.
If it's only at the end of the application, just make them background
threads when you start them - then they'll just die automatically.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too