J
Jon Slaughter
Is there any way to start a terminated thread without using a pool or
creating a new thread object?
void counter()
{
clicks = 0;
clock.Start();
while (counterActive)
{
clicks++;
Thread.SpinWait(counterWaits);
}
clock.Stop();
}
double PointProfiler(int waits, int sleep)
{
counterWaits = waits;
while (counterThread.IsAlive) counterActive = false;
counterActive = true; clicks = 0;
counterThread.Start();
Thread.Sleep(sleep);
while (counterThread.IsAlive) counterActive = false;
return clicks / clock.Time;
}
I want to be able to start the counter thread each time but not create a new
thread(because of the performance overhead). I also don't want the counter
to run for ever so I need a way of restarting it. It seems that this is
impossible though? ;/
Is there any way to make it so that the thread is re-entrant? I tried to
suspend but suspend is obsolete and isn't working. If I do .Start() then
..Suspend() right after it I get 100% cpu usage as if it didn't suspend
anything.
It seems that I have no choice but to use a pool but I think that it might
cause some performance issues(I'm trying to time things as accurate as
possible). I can do what I want to do if I can let the counter thread run
continuously but now since I'm trying to integrate it as part of a gui I
need to only let it run when its needed. (and I think that creating a new
thread every time I need to do this is out of the questing(since I'll be
profiling several times in a row).
creating a new thread object?
void counter()
{
clicks = 0;
clock.Start();
while (counterActive)
{
clicks++;
Thread.SpinWait(counterWaits);
}
clock.Stop();
}
double PointProfiler(int waits, int sleep)
{
counterWaits = waits;
while (counterThread.IsAlive) counterActive = false;
counterActive = true; clicks = 0;
counterThread.Start();
Thread.Sleep(sleep);
while (counterThread.IsAlive) counterActive = false;
return clicks / clock.Time;
}
I want to be able to start the counter thread each time but not create a new
thread(because of the performance overhead). I also don't want the counter
to run for ever so I need a way of restarting it. It seems that this is
impossible though? ;/
Is there any way to make it so that the thread is re-entrant? I tried to
suspend but suspend is obsolete and isn't working. If I do .Start() then
..Suspend() right after it I get 100% cpu usage as if it didn't suspend
anything.
It seems that I have no choice but to use a pool but I think that it might
cause some performance issues(I'm trying to time things as accurate as
possible). I can do what I want to do if I can let the counter thread run
continuously but now since I'm trying to integrate it as part of a gui I
need to only let it run when its needed. (and I think that creating a new
thread every time I need to do this is out of the questing(since I'll be
profiling several times in a row).