PC Review


Reply
Thread Tools Rate Thread

create and wait for multiple processes

 
 
colson
Guest
Posts: n/a
 
      14th Jun 2006
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

 
Reply With Quote
 
 
 
 
Michael Nemtsev
Guest
Posts: n/a
 
      14th Jun 2006
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


 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      14th Jun 2006

"colson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
|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.



 
Reply With Quote
 
Ben Voigt
Guest
Posts: n/a
 
      15th Jun 2006

"Willy Denoyette [MVP]" <(E-Mail Removed)> wrote in message
news:efv6dK$(E-Mail Removed)...
>
> "colson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> |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.
>
>
>



 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      15th Jun 2006

"Ben Voigt" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
|
| "Willy Denoyette [MVP]" <(E-Mail Removed)> wrote in message
| news:efv6dK$(E-Mail Removed)...
| >
| > "colson" <(E-Mail Removed)> wrote in message
| > news:(E-Mail Removed)...
| > |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.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can the Application.wait method create a pause less than a second? Gum Microsoft Excel Programming 2 3rd Oct 2008 01:09 PM
Wait on Multiple Threads in c# Prasad Microsoft C# .NET 1 8th Aug 2005 08:10 AM
"Please wait while Microsoft Outlook Exits" - and wait, and wait, and wait... steŠ Microsoft Outlook Discussion 5 4th Jul 2004 05:34 PM
Multiple services, in multiple processes, but a single assembly Microsoft Dot NET Framework 1 6th Apr 2004 06:58 AM
Create Process and Wait Peter Microsoft C# .NET 7 15th Mar 2004 01:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:04 PM.