Click here to Skip to main content
15,898,588 members
Home / Discussions / C#
   

C#

 
GeneralRe: Remoting (events/delegates) Pin
leppie16-Jan-03 10:56
leppie16-Jan-03 10:56 
QuestionHow to use the SqlClientPermission? Pin
shanelhatcher13-Jan-03 7:48
shanelhatcher13-Jan-03 7:48 
AnswerRe: How to use the SqlClientPermission? Pin
leppie13-Jan-03 9:44
leppie13-Jan-03 9:44 
GeneralRe: How to use the SqlClientPermission? Pin
shanelhatcher14-Jan-03 8:02
shanelhatcher14-Jan-03 8:02 
GeneralFullscreen Alt-Tab problem in ManagedD3D Pin
Zinj13-Jan-03 2:22
sussZinj13-Jan-03 2:22 
GeneralRe: Windows Service & Console Server application Pin
Kannan Kalyanaraman13-Jan-03 1:14
Kannan Kalyanaraman13-Jan-03 1:14 
Generalrun external programm and catch results Pin
Daishi100213-Jan-03 0:11
Daishi100213-Jan-03 0:11 
GeneralRe: run external programm and catch results Pin
Daishi100213-Jan-03 0:58
Daishi100213-Jan-03 0:58 
As usual i found the answer myself, sorry for posting so early ...

This is an extract from MS .NET Help:

Greets Daishi1002
################################

The Process component communicates with a child process via a pipe. If a child process writes enough data to the pipe to fill the buffer, the child will block until the parent reads the data from the pipe. This can cause deadlock if your application is reading all output to standard error and standard output, for example, using the following C# code.

[C#]
Process p = new Process("...", "...");
p.UseShellExecute = false;
p.RedirectStandardOutput = true;
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
In this instance, both the parent and the child processes would be blocked, as the filled pipe prevents the child process from completing, while the parent process is waiting indefinitely for the child process to exit.

This problem can be solved by moving the ReadToEnd() before the WaitForExit(), as follows.

[C#]
Process p = new Process("...", "...");
p.UseShellExecute = false;
p.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
A similar problem arises if you redirect both standard output and standard error and then try to read both, for example using the following C# code.

[C#]
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
p.WaitForExit();
In this case, if the child process writes any text to standard error it will block the process, because the parent process cannot read from standard error until it has finished reading from standard output. However, the parent process will not read from standard output until the process ends. A recommended solution to this situation is to create two threads so that your application can read the output of each stream on a separate thread.


GeneralBest COM and .NET interop book Pin
Oyvind Bratland12-Jan-03 21:18
Oyvind Bratland12-Jan-03 21:18 
GeneralRe: Best COM and .NET interop book Pin
Jarrod Marshall13-Jan-03 7:42
Jarrod Marshall13-Jan-03 7:42 
GeneralCreate Shortcut (.lnk) Pin
CyberKewl12-Jan-03 17:10
CyberKewl12-Jan-03 17:10 
GeneralRe: Create Shortcut (.lnk) Pin
Kannan Kalyanaraman13-Jan-03 1:10
Kannan Kalyanaraman13-Jan-03 1:10 
GeneralRe: Create Shortcut (.lnk) Pin
CyberKewl13-Jan-03 2:26
CyberKewl13-Jan-03 2:26 
GeneralAnother Question [They just keep comin :)] Pin
Nnamdi Onyeyiri12-Jan-03 8:52
Nnamdi Onyeyiri12-Jan-03 8:52 
GeneralRe: Another Question [They just keep comin :)] Pin
leppie12-Jan-03 9:50
leppie12-Jan-03 9:50 
GeneralRe: Another Question [They just keep comin :)] Pin
Nnamdi Onyeyiri12-Jan-03 9:53
Nnamdi Onyeyiri12-Jan-03 9:53 
GeneralRe: Another Question [They just keep comin :)] Pin
David Stone12-Jan-03 10:40
sitebuilderDavid Stone12-Jan-03 10:40 
GeneralRe: Another Question [They just keep comin :)] Pin
James T. Johnson12-Jan-03 11:40
James T. Johnson12-Jan-03 11:40 
GeneralRe: Another Question [They just keep comin :)] Pin
David Stone12-Jan-03 14:23
sitebuilderDavid Stone12-Jan-03 14:23 
GeneralRe: Another Question [They just keep comin :)] Pin
Nnamdi Onyeyiri13-Jan-03 5:37
Nnamdi Onyeyiri13-Jan-03 5:37 
GeneralRe: Another Question [They just keep comin :)] Pin
David Stone13-Jan-03 9:42
sitebuilderDavid Stone13-Jan-03 9:42 
GeneralRe: Another Question [They just keep comin :)] Pin
leppie13-Jan-03 9:47
leppie13-Jan-03 9:47 
GeneralColour Names Pin
Nnamdi Onyeyiri12-Jan-03 7:30
Nnamdi Onyeyiri12-Jan-03 7:30 
GeneralRe: Colour Names Pin
leppie12-Jan-03 8:29
leppie12-Jan-03 8:29 
GeneralRe: Colour Names Pin
Nnamdi Onyeyiri12-Jan-03 8:34
Nnamdi Onyeyiri12-Jan-03 8:34 

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.