I need to restart the completed stream. The thread is in the (stopped) state. How to restart it?

void Work1() { while(!terminate) { Thread.Sleep(rnd.Next(5)); } } 
  • It is not clear what you want. Take the stream out of Sleep? To complete? Launch a new one? What problem are you solving? - VladD
  • The fact is that I am completing the stream by assigning terminate = true, but I want to restart this thread without re-creating the stream instance. Is it possible? - Mirlan
  • Not. The thread runs only once, you can only create a new thread after the old one is completed. - VladD
  • @ Mirlan If the flow is already stopped (i.e. its main function is completed) then it seems that it can no longer be resumed, but you can do this — wrap the body into a perpetual loop function, at the end of the cycle just put the flow in Sleep as you did above at the same time through some kind of variable to give a signal that the flow would go out of Sleep and go to the next iteration to the very beginning, in the end you will get an eternal flow that will do the work, put to sleep and re-awaken on command. - Arty OneSoul

0