1

The problem is created several process and start them using process.start() and now i have to move these processes between states. but the thing is I cant use the Thread.Suspend() i think.

So how can I suspend these processes and then resume them?

private void button1_Click(object sender, EventArgs e)
{
    var process1 = new Process();
    var process2 = new Process();
    var process3 = new Process();
    process1.StartInfo.FileName = "proc1";
    process2.StartInfo.FileName = "proc2";
    process3.StartInfo.FileName = "proc3";
    process1.Start();
    process2.Start();
    process3.Start();
}

these 3 processes are C# programs (.exe) that I created to read and write into different files.

Ilya Ivanov
  • 23,148
  • 4
  • 64
  • 90
Wissam Habib
  • 9
  • 1
  • 7
  • 6
    Have you considered other questions like http://stackoverflow.com/questions/71257/suspend-process-in-c-sharp?rq=1 ? – Ilya Ivanov Jan 12 '13 at 11:28
  • yes I've seen this, but it's too complicated. I was wondering if there was an easier way (bcz honestly i didnt really understand what was going in in that program) – Wissam Habib Jan 12 '13 at 11:33
  • process communication is not quite easy topic. If you provide some relevant code examples with deep motivations, then we will have more information to give a more coherent answer. – Ilya Ivanov Jan 12 '13 at 11:34
  • my problem is that this is the only code i have in my main program: private void button1_Click(object sender, EventArgs e) { Process process1 = new Process(); Process process2 = new Process(); Process process3 = new Process(); process1.StartInfo.FileName = "proc1"; process2.StartInfo.FileName = "proc2"; process3.StartInfo.FileName = "proc3"; process1.Start(); process2.Start(); process3.Start(); } processes are C# programs to write and read into a file – Wissam Habib Jan 12 '13 at 11:38
  • 1
    move your code into answer, not comment. And please consider formatting it in a decent way – Ilya Ivanov Jan 12 '13 at 11:40
  • i cant answer my question cuz im new here. but it only creates 3 new process and launches them – Wissam Habib Jan 12 '13 at 11:43
  • No need to answer it, you need to edit your question. Check the edit link below the tags in your question. – Ravi Y Jan 12 '13 at 11:45
  • ok done, sorry for bothering, but i really have no idea about what i can do. and ive searched alot – Wissam Habib Jan 12 '13 at 11:47
  • Good. Now the main question is **why** do you want to create three different processes? Why **Thread** won't do it? Why single thread won't do it? Why naive synchronous implementation won't do it? – Ilya Ivanov Jan 12 '13 at 11:49
  • it is for a class project. I know it makes no sense, and that's why It's so hard for me to solb=ve – Wissam Habib Jan 12 '13 at 12:10

1 Answers1

3

You should not think about suspending and resuming a process. Because this is not how you are supposed to manage Windows processes. You can theoretically suspend all the threads, but why? If a thread doesn't have work to do, it is not scheduled for execution. Likewise, a process, if it doesn't have work - it merely uses some memory for state representation, but it doesn't consume any CPU.

Rethink your architecture in favour of standard process communication approaches or process management. For example there are Windows jobs, WCF with interprocess communication, database interactions.

oleksii
  • 35,458
  • 16
  • 93
  • 163