How to start a stopped thread

前端 未结 5 2053
孤城傲影
孤城傲影 2021-02-14 10:53

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         


        
5条回答
  •  余生分开走
    2021-02-14 11:09

    Use a ManualResetEvent, and instead of Thread.Sleep, wait for the event with a timeout.

    Then, any other thread can activate the event, and immediately resume the sleeping thread.

    Once a thread is exited, it can no longer run. So don't let it exit. Instead, put it back to sleep waiting for an event.

提交回复
热议问题