469,097 Members | 1,274 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,097 developers. It's quick & easy.

create and wait for multiple processes

I know how to create a new process using System.Diagnostics.Process and
wait for the process to end using WaitForExit(). How do I wait for
multiple processes? Is there an equivalent to WaitForMultipleObjects
under .NET?

Thanks

Jun 14 '06 #1
4 8818
Hello colson,

See MSDN for WaitHandle.WaitAny() method

c> I know how to create a new process using System.Diagnostics.Process
c> and wait for the process to end using WaitForExit(). How do I wait
c> for multiple processes? Is there an equivalent to
c> WaitForMultipleObjects under .NET?
c>
c> Thanks
c>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jun 14 '06 #2

"colson" <ch******@gmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
|I know how to create a new process using System.Diagnostics.Process and
| wait for the process to end using WaitForExit(). How do I wait for
| multiple processes? Is there an equivalent to WaitForMultipleObjects
| under .NET?
|
| Thanks
|

Yes there is an equivalent but it's not applicable here,
WaitForMultipleObjects waits for kernel objects to be signaled, while
WaitForExit waits for a processes to exit. All you need to do is create a
separate thread for each process you need to start and wait for.
Willy.

Jun 14 '06 #3

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:ef**************@TK2MSFTNGP04.phx.gbl...

"colson" <ch******@gmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
|I know how to create a new process using System.Diagnostics.Process and
| wait for the process to end using WaitForExit(). How do I wait for
| multiple processes? Is there an equivalent to WaitForMultipleObjects
| under .NET?
|
| Thanks
|

Yes there is an equivalent but it's not applicable here,
WaitForMultipleObjects waits for kernel objects to be signaled, while
WaitForExit waits for a processes to exit. All you need to do is create a
separate thread for each process you need to start and wait for.
Yeeech. Processes are kernel objects, and WaitForMultipleObjects handles
them just fine.

WaitHandle.WaitAll would work if Process had a WaitHandle property. But it
doesn't, and the ProcessWaitHandle class is internal to System.dll.
However, if you can get a WaitHandle from somewhere (WaitHandle is abstract
so new WaitHandle() won't work), you can reassign its Handle property to the
Process object's Handle property, and then use WaitHandle.WaitAll.

Or get the process objects' Handle properties, stuff 'em into an array, and
p/invoke WaitForMultipleObjects.

http://pinvoke.net/default.aspx/kern...leObjects.html


Willy.

Jun 14 '06 #4

"Ben Voigt" <rb*@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
|
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:ef**************@TK2MSFTNGP04.phx.gbl...
| >
| > "colson" <ch******@gmail.com> wrote in message
| > news:11**********************@c74g2000cwc.googlegr oups.com...
| > |I know how to create a new process using System.Diagnostics.Process and
| > | wait for the process to end using WaitForExit(). How do I wait for
| > | multiple processes? Is there an equivalent to WaitForMultipleObjects
| > | under .NET?
| > |
| > | Thanks
| > |
| >
| > Yes there is an equivalent but it's not applicable here,
| > WaitForMultipleObjects waits for kernel objects to be signaled, while
| > WaitForExit waits for a processes to exit. All you need to do is create
a
| > separate thread for each process you need to start and wait for.
|
| Yeeech. Processes are kernel objects, and WaitForMultipleObjects handles
| them just fine.

Sorry, bad wording, I didn't mean to suggest that processes aren't kernel
objects.
|
| WaitHandle.WaitAll would work if Process had a WaitHandle property. But
it
| doesn't, and the ProcessWaitHandle class is internal to System.dll.

That's what I meant when I said it's not applicable here, there is no
publically exposed WaitHandle, 'would work if .. " isn't very usefull here.
| However, if you can get a WaitHandle from somewhere (WaitHandle is
abstract
| so new WaitHandle() won't work), you can reassign its Handle property to
the
| Process object's Handle property, and then use WaitHandle.WaitAll.
|

Sure you can do this by grabing the process handle, but it isn't that simple
as it may look like if you want to make it safe and solid. Just look at the
WaitForExit to get an idea of what (partly) should be done.

| Or get the process objects' Handle properties, stuff 'em into an array,
and
| p/invoke WaitForMultipleObjects.
|
| http://pinvoke.net/default.aspx/kern...leObjects.html
|

No, thanks, I stay with my suggestion - one thread per process (I suppose
the OP isn't going to start hundreds of process that way), I prefer not to
go down a PInvoke hack when I don't have to.

Willy.

Jun 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Markus Franz | last post: by
29 posts views Thread by Paul L. Du Bois | last post: by
22 posts views Thread by Brett Romero | last post: by
22 posts views Thread by Jason Zheng | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.