How to start a stopped thread

前端 未结 5 2064
孤城傲影
孤城傲影 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:03

    To restart a thread, try this:

    private void button1_Click(object sender, EventArgs e)
    {
        // Just create a new constructor for the stopped Thread
        m_MyThread = null;
        m_MyThread = new Thread(HandleMyThread);
        m_MyThread.IsBackground = true;
        // Then restart the stopped Thread
        m_MyThread.Start();
    }
    

    This works if the thread was previously stopped.

提交回复
热议问题