Click here to Skip to main content
15,917,176 members
Home / Discussions / C#
   

C#

 
AnswerRe: Scheduling tasks Pin
led mike26-Mar-09 6:10
led mike26-Mar-09 6:10 
AnswerRe: Scheduling tasks Pin
Henry Minute26-Mar-09 6:13
Henry Minute26-Mar-09 6:13 
QuestionThreading in C# with a Console Application Pin
agent00zelda26-Mar-09 4:58
agent00zelda26-Mar-09 4:58 
AnswerRe: Threading in C# with a Console Application Pin
Deresen26-Mar-09 6:00
Deresen26-Mar-09 6:00 
GeneralRe: Threading in C# with a Console Application Pin
agent00zelda26-Mar-09 6:55
agent00zelda26-Mar-09 6:55 
GeneralRe: Threading in C# with a Console Application Pin
S. Senthil Kumar27-Mar-09 7:12
S. Senthil Kumar27-Mar-09 7:12 
Questionhow to connect/query assisted gps server Pin
hammid198126-Mar-09 4:26
hammid198126-Mar-09 4:26 
QuestionHow to wait for process with redirected Output (asynchronous) end AND end of output stream WITH timeout for process? Pin
MayFlyJJ26-Mar-09 4:02
MayFlyJJ26-Mar-09 4:02 
Hi Folks,

since 3 days I am reading and thinking about how to implement (.NET 2.0) an asynchronous output stream of a process with making sure, that I can kill the process after a timeout AND that I have read everything from the output buffer?

some code (better than 1000 words Wink | ;) :

cmdProcess.StartInfo.FileName = cmd;
cmdProcess.StartInfo.UseShellExecute = false;
cmdProcess.StartInfo.ErrorDialog = false;
cmdProcess.StartInfo.RedirectStandardOutput = true;
cmdProcess.StartInfo.RedirectStandardError = true;
cmdProcess.StartInfo.CreateNoWindow = true;
cmdProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmdProcess.OutputDataReceived += new DataReceivedEventHandler(cmdProcess_OutputDataReceived);
cmdProcess.ErrorDataReceived += new DataReceivedEventHandler(cmdProcess_ErrorDataReceived);

cmdProcess.Start();

cmdProcess.BeginErrorReadLine();
cmdProcess.BeginOutputReadLine();

cmdProcess.WaitForExit(_timeoutForWZZipOperation);


if (cmdProcess.HasExited)
{
(A)
[...]
}
else
{
cmdProcess.Kill();
[...]
}

In point (A) I want to be sure, that the complete output buffer has been proceeded.
Some additional thoughts and explanations:
I am starting WZZip (winzip command line) to display the content of a zip file (I HAVE to use wzzip, so I cannot switch to .net zipper etc.). The output is longer than the buffer, therefore I have to read asynchronous when I want to write the output as soon as possible in a log file. Additionally I have to use WaitForExit, because the security policies for this program are quite high and I need to continue with program, even if wzzip hangs (another reason to use asynchronous output, otherwise the program would not continue, because nobody is closing the outputstream).

I hope my explanation is understandable Wink | ;-) In short words, I have following requirements:
- Log output to file as soon as possible
- Timeout for process to handle crashes/hangs
- when process has exited, I have to be sure, that the output (and error) stream is empty before I continue with my program
- Thread.Sleep (x); is no option, because I have > 100.000 files to scan (I need the quickest way)

Sine 3 days I am climbing up walls, because whenever I have read something nice, some of the other requirements are not fulfilled... I really hope you can give me a hint (or maybe I am just thingink in the wrong direction)!

Thanks a lot!!!

Brgds,
Michael
AnswerRe: How to wait for process with redirected Output (asynchronous) end AND end of output stream WITH timeout for process? [modified] Pin
Luc Pattyn26-Mar-09 5:21
sitebuilderLuc Pattyn26-Mar-09 5:21 
GeneralRe: How to wait for process with redirected Output (asynchronous) end AND end of output stream WITH timeout for process? Pin
MayFlyJJ26-Mar-09 6:17
MayFlyJJ26-Mar-09 6:17 
GeneralRe: How to wait for process with redirected Output (asynchronous) end AND end of output stream WITH timeout for process? Pin
Luc Pattyn26-Mar-09 7:17
sitebuilderLuc Pattyn26-Mar-09 7:17 
GeneralRe: How to wait for process with redirected Output (asynchronous) end AND end of output stream WITH timeout for process? Pin
MayFlyJJ27-Mar-09 2:07
MayFlyJJ27-Mar-09 2:07 
GeneralRe: How to wait for process with redirected Output (asynchronous) end AND end of output stream WITH timeout for process? Pin
Luc Pattyn27-Mar-09 2:24
sitebuilderLuc Pattyn27-Mar-09 2:24 
QuestionDynamic Link Button not firing click event. Pin
Kevin Mauriello26-Mar-09 3:50
Kevin Mauriello26-Mar-09 3:50 
Questionchanging the database after addition to the project ? Pin
Mubeen.asim26-Mar-09 3:36
Mubeen.asim26-Mar-09 3:36 
AnswerRe: changing the database after addition to the project ? Pin
Vimalsoft(Pty) Ltd26-Mar-09 4:14
professionalVimalsoft(Pty) Ltd26-Mar-09 4:14 
GeneralRe: changing the database after addition to the project ? Pin
Mubeen.asim26-Mar-09 4:50
Mubeen.asim26-Mar-09 4:50 
GeneralRe: changing the database after addition to the project ? Pin
Vimalsoft(Pty) Ltd26-Mar-09 4:57
professionalVimalsoft(Pty) Ltd26-Mar-09 4:57 
GeneralRe: changing the database after addition to the project ? Pin
Mubeen.asim26-Mar-09 5:01
Mubeen.asim26-Mar-09 5:01 
GeneralRe: changing the database after addition to the project ? Pin
Vimalsoft(Pty) Ltd26-Mar-09 5:07
professionalVimalsoft(Pty) Ltd26-Mar-09 5:07 
GeneralRe: changing the database after addition to the project ? Pin
Mubeen.asim26-Mar-09 6:39
Mubeen.asim26-Mar-09 6:39 
GeneralRe: changing the database after addition to the project ? Pin
Vimalsoft(Pty) Ltd26-Mar-09 19:57
professionalVimalsoft(Pty) Ltd26-Mar-09 19:57 
Questionhow to disable globel mouse and Keyboard event.. [modified] Pin
prem194226-Mar-09 3:30
prem194226-Mar-09 3:30 
GeneralPerformance problem when implementing driversin state machine model Pin
ayyappa4902126-Mar-09 3:12
ayyappa4902126-Mar-09 3:12 
QuestionIcons Disapear from taskebar Pin
udikantz26-Mar-09 2:59
udikantz26-Mar-09 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.