J
Jon Slaughter
I'm using Thread and ThreadStart to create a thread for testing purposes and
I do not want to use a pool because the thread exists for the life time of
the app. Eventually I might move on to using pools but at this point I'm
just testing some timing issues.
in any cause the thread is simply a counter,
static void counter()
{
while (true)
{
clicks++;
//Delayer(10000);
//Thread.Sleep(0);
Thread.SpinWait(100);
}
}
Now my main program "profiles" this thread by computing how many clicks it
does in a specified time. It does this and does some statistics and then
returns a result and then tries to exit. The problem is, when I use SpinWait
as a delayer my app never exists but just sits there. If I use Delayer then
I can abort the thread and everything works fine. I do understand abort
isn't the best way but in this case I don't really have any other option
that I know of. What else can I do besides use pools?
Every site I have visted says that Thread.Abort is evil yet how else can you
stop a thread(I know theres a scope issue but in this case its not working
either).
I'd like to use SpinWait since it seems to be slightly more stable than my
delayer(which is a unmanaged C++ function that uses nops)... But doesn't do
me any good if I can't stop the thread with it ;/
Any ideas?
Thanks,
Jon
I do not want to use a pool because the thread exists for the life time of
the app. Eventually I might move on to using pools but at this point I'm
just testing some timing issues.
in any cause the thread is simply a counter,
static void counter()
{
while (true)
{
clicks++;
//Delayer(10000);
//Thread.Sleep(0);
Thread.SpinWait(100);
}
}
Now my main program "profiles" this thread by computing how many clicks it
does in a specified time. It does this and does some statistics and then
returns a result and then tries to exit. The problem is, when I use SpinWait
as a delayer my app never exists but just sits there. If I use Delayer then
I can abort the thread and everything works fine. I do understand abort
isn't the best way but in this case I don't really have any other option
that I know of. What else can I do besides use pools?
Every site I have visted says that Thread.Abort is evil yet how else can you
stop a thread(I know theres a scope issue but in this case its not working
either).
I'd like to use SpinWait since it seems to be slightly more stable than my
delayer(which is a unmanaged C++ function that uses nops)... But doesn't do
me any good if I can't stop the thread with it ;/
Any ideas?
Thanks,
Jon