Home > Enterprise >  Start Thread multiple times
Start Thread multiple times

Time:10-11

I want to use a thread to upload a file to a server.

As long as the ThreadState is Unstarted, I can use ThreadName.Start() to start the thread. When the code is finished the ThreadState gets Stopped. How can I start that thread again?

My thread looks like this:

public static Thread ThreadUploadFile = new Thread(() =>
{
    // Upload file
});

I call the thread by:

private void UploadFile()
{
    ThreadUploadFile.Start();
});

CodePudding user response:

You cannot.

Once the thread is stopped then it can never leave that state. You must initialise a new instance and run that new instance.

See enter image description here

CodePudding user response:

You cannot start the Thread again once it is stopped. I recommend to turn your anonymous method into a real method and create a new Thread each time before starting.

  • Related