Thread.Suspend()the method is deprecated, as you know. I want to temporarily suspend a stream when a button is pressed. I used Thread.Suspend () and it works great, but everyone thinks that using the Thread.Suspend () method is not a good method to pause a task. I used the flag to pause the task, but every time a button click event arrives, I have to wait to exit the task. I used the Thread.IsAlive flag to wait for the thread to exit, but this method freezes the form.
void ButtonClickEvent(object sender, ButtonClickEventArgs e)
{
TheadExitFlag = false;
if(MyThread != null)
{
while(MyThread.IsAlive);
}
}
void MyTask(void)
{
while(TheadExitFlag)
{
Thread.Sleep(5000);
}
}
How can I temporarily suspend a thread?
source
share