How to start a stopped thread

Viewed 29502

I create a new thread and start it from a main thread.

m_MyThread = new Thread(HandleMyThread);
m_MyThread.IsBackground = true;
m_MyThread.Start();

private void HandleMyThread()
{
    while (true)
    {
        Thread.Sleep(5000);
        return;
    }
}

After 5 seconds, this thread will finish and its ThreadState is Stopped. I want to start it again when user clicks on button but I get a ThreadStateException (Thread is running or terminated; it cannot restart):

private void button1_Click(object sender, EventArgs e)
{
    m_MyThread.Start(); // ->raise exception
}

Please help me how to restart a stopped thread. Thanks.

4 Answers
Related