0

If I want to run a process (say: KindleGen.exe filename using Process.Start()) multiple times at the same time (using threads), is that possible?

I guess the real/summarized question is: can i run a process multiple times at the same time by launching it multiple times at the same time from different threads?

will it launch multiple processes or give an error that a process with the same name is already running? are there any special parameters i need to pass to Process.Start() to make this happen/work?

MaxOvrdrv
  • 1,780
  • 17
  • 32
  • 2
    You may as well just launch multiple processes from a single thread and let the OS worry about threading/scheduling their execution. Each process will end up with (at least) one thread anyway. – James Thorpe Aug 03 '15 at 15:56
  • 1
    Also, if the app wont let you have more than one copy, you wont get a second. You might if you launch each copy as a diferent user. – BugFinder Aug 03 '15 at 15:59
  • 1
    There is nothing stopping Windows from running multiple applications with the same name (ever open 2 web browsers? 2 instances of Visual Studio?). Starting the processes from different threads doesn't mean they run inside the thread you start them in, the OS spawns new processes (and new threads) to run them. The only thing that may stop it is if the application itself won't run multiple instances (like outlook). – Ron Beyer Aug 03 '15 at 16:06

1 Answers1

2

Yes, you can run a process multiple times at the same time.

Process.Start() will do this. The return value true indicates that a new process was started.

A process, in the simplest terms, is an executing program. One or more threads run in the context of the process. By starting a process you are implicitly creating (at least one) new thread.

Sam Greenhalgh
  • 5,952
  • 21
  • 37
  • alright... and how would i keep track of the process that got launched from each of my threads and wait for an exit before moving onto the next file? – MaxOvrdrv Aug 03 '15 at 16:08
  • @MaxOvrdrv, [WaitForSingleObject](https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx) – Mark Shevchenko Aug 03 '15 at 16:13
  • @MarkShevchenko i do not know how long the process can and will take... is there not a simpler way to wait for the process to exit and catch the return value? i guess i could look that up separately. thanks! – MaxOvrdrv Aug 03 '15 at 16:17
  • @MaxOvrdrv Use `INFINITY` in `WaitForSingleObject` as `milliseconds` parameter. Use `GetExitCodeProcess ` when `WaitForSingleObject` will terminate. – Mark Shevchenko Aug 03 '15 at 16:38
  • @MarkShevchenko i also found an answer here... http://stackoverflow.com/questions/3147911/wait-till-a-process-ends i'm sure the OSAPI uses this same function, but this is simpler... basically, assign ``Process.Start()`` to a variable, and then call ``WaitForExit()`` on the variable. – MaxOvrdrv Aug 03 '15 at 16:47