K
kiplring
Suppose a function which has Sleep() method in it. And I want to
recycle it. I made two buttons which call "Resume()" and "Suspend()".
But It doesn't work. The state of thread "t" will be "WaitSleepJoin"
when it runs because the function it calls - "GenerateEvents()" has
"Sleep()" function.
Can I solve this problem with Thread? I don't want add nasty boll flags
on it.
public class Test
{
private ThreadStart ts = null;
private Thread t = null;
private void GenerateEvents()
{
while(true)
{
SendClick( MousePosition);
Thread.Sleep(500);
}
}
public Test()
{
ts = new ThreadStart( GenerateClicks);
t = new Thread( ts);
t.Start();
}
public Resume()
{
if( t.ThreadState == ThreadState.Suspend)
{
t.Resume();
}
}
public Suspend()
{
if( t.ThreadState != ThreadState.Suspend)
{
t.Suspend();
}
}
}
recycle it. I made two buttons which call "Resume()" and "Suspend()".
But It doesn't work. The state of thread "t" will be "WaitSleepJoin"
when it runs because the function it calls - "GenerateEvents()" has
"Sleep()" function.
Can I solve this problem with Thread? I don't want add nasty boll flags
on it.
public class Test
{
private ThreadStart ts = null;
private Thread t = null;
private void GenerateEvents()
{
while(true)
{
SendClick( MousePosition);
Thread.Sleep(500);
}
}
public Test()
{
ts = new ThreadStart( GenerateClicks);
t = new Thread( ts);
t.Start();
}
public Resume()
{
if( t.ThreadState == ThreadState.Suspend)
{
t.Resume();
}
}
public Suspend()
{
if( t.ThreadState != ThreadState.Suspend)
{
t.Suspend();
}
}
}