[Mono-list] Strange timing issue when reading ExitCode from spawned process

Patrick Fernie pfernie at jwmp.com
Wed May 9 18:24:08 EDT 2007


I'm having some weird behavior with processes being spawned and getting
the ExitCode of that process. Sample code can be seen at
http://pastebin.ca/479814. This code is a simplification of a much more
complex system we have. Basically, we have a job distribution and
logging system that controls processes launching on remote machines.
This much simplified version simply spawns a process (a simple program
that returns as its exit code the parameter passed to it), polls
HasExited on that Process object until true, and then reads the
ExitCode. If a trivial WaitForExit(1) is placed after the call to
Start(), the ExitCode can be read fine. If not, the ExitCode comes back
0. If a Sleep() call is used to delay reading the ExitCode, it will once
again get the proper exit code. If, as the sample pasted shows, you
sleep for even up to 5 seconds, poll the ExitCode, it will be 0, but
wait another 5 seconds and poll again, and the ExitCode will be set.
This seems like some odd timing behavior; is this in any way expected? I
did a quick search and didn't really find mention of this bug/behavior.
If there is a valid reason for it, is there a known way to properly
recover the ExitCode? (WaitForExit(1) is our current solution, but seems
less that optimal!). Basically, it seems to me that the ExitCode should
be populated as soon as/before HasExited becomes true.

 

-Patrick

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070509/8196f1d4/attachment.html 


More information about the Mono-list mailing list