473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 9135
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Markus Franz | last post by:
Hi. I created a little script: for currenturl in sys.argv: pid = os.fork() if pid == 0: signal.alarm(10) do_something() # placeholder for the download and print routine
29
by: Paul L. Du Bois | last post by:
Has anyone written a Queue.Queue replacement that avoids busy-waiting? It doesn't matter if it uses os-specific APIs (eg WaitForMultipleObjects). I did some googling around and haven't found...
9
by: cantelow | last post by:
Hi. I've got a program printing multiple pdf reports, and I need to wait for completion of various associated operations- The pdf printer prints to one file, then I need to copy that where I need...
2
by: Brett | last post by:
What are the advantages/disadvantages of using one process with multiple threads or doing the same task with multiple processes, each having one thread? I see using multiple threads under one...
22
by: Brett Romero | last post by:
If my UI app uses three DLLs and two of those DLLs reference something named utilities.dll, does the UI app load utilities.dll twice or does the compiler recognize what is going on and load...
2
by: comp.lang.php | last post by:
I have an app that is going berzerk on its own; without any code or environmental changes of any kind, for some bizarre reason it will randomly just hang, spawn multiple Apache processes and...
22
by: Jason Zheng | last post by:
This may be a silly question but is possible for os.wait() to lose track of child processes? I'm running Python 2.4.4 on Linux kernel 2.6.20 (i686), gcc4.1.1, and glibc-2.5. Here's what happened...
1
by: jazon | last post by:
Let me start by saying this for an Operating Systems class. No, I don't expect the work to be done for me. The assignment is as follows: To be honest, I feel like a fish out of water, like...
0
by: jeremyje | last post by:
I would like to create an application where I have many concurrent processes being managed by a monitoring process. Each process that is "managed" will be invoked from an assembly dll (think...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.