Click here to Skip to main content
15,895,538 members
Home / Discussions / C#
   

C#

 
GeneralRe: Entity Model Insert Help Pin
ToddHileHoffer3-Sep-09 6:52
ToddHileHoffer3-Sep-09 6:52 
QuestionMemory leak on Lucene.net 2.3.2 Pin
susantasamanta853-Sep-09 5:20
susantasamanta853-Sep-09 5:20 
AnswerRe: Memory leak on Lucene.net 2.3.2 Pin
Henry Minute3-Sep-09 5:33
Henry Minute3-Sep-09 5:33 
Questionsend data to website Pin
Omar Gameel Salem3-Sep-09 5:16
professionalOmar Gameel Salem3-Sep-09 5:16 
AnswerRe: send data to website Pin
Eddy Vluggen3-Sep-09 7:12
professionalEddy Vluggen3-Sep-09 7:12 
GeneralRe: send data to website Pin
Omar Gameel Salem3-Sep-09 7:58
professionalOmar Gameel Salem3-Sep-09 7:58 
QuestionSystem.Diagnostics.Process, asyncronous reading StandardOutput and StandardError streams Pin
Jon Hulatt3-Sep-09 5:03
Jon Hulatt3-Sep-09 5:03 
AnswerRe: System.Diagnostics.Process, asyncronous reading StandardOutput and StandardError streams Pin
Heath Higgins9-Sep-09 13:10
Heath Higgins9-Sep-09 13:10 
Hi Jon,

I've been struggling with this one for a while myself and was able to create a scenario where standard out/err data were not handled by dumping a large number of lines from the process right before exiting. I had hoped to be able to switch from asynchronous to synchronous reads once the WaitForExit() returns, and then receive the remaining data with a process.StandardOutput.ReadToEnd(). Unfortunately, this is not possible:

"You cannot mix asynchronous and synchronous read operations on the redirected StandardOutput stream. Once the redirected stream of a Process is opened in either asynchronous or synchronous mode, all further read operations on that stream must be in the same mode. If you cancel an asynchronous read operation on StandardOutput and then need to read from the stream again, you must use BeginOutputReadLine to resume asynchronous read operations. Do not follow CancelOutputRead with a call to the synchronous read methods of StandardOutput such as Read, ReadLine, or ReadToEnd."
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.canceloutputread.aspx[^]

As far as I can tell, this applies to anything you could check (process.StandardOutput.EndOfStream) to see if it were necessary for you to delay cleanup. Unless I'm missing something, which is entirely possible, this seems like a shortcoming of the Process class, because it essentially means that you can't trust the asynchronous interface to provide you with all of your data.

Sadly, this seems to leave us with synchronous IO, perhaps a couple extra threads, and the additional synchronization issues that this approach entails (see here[^] for a deadlock condition to watch out for).

The only other thing that has worked for me so far, and this is sort of hackish, is to sleep the thread that handles the Exited event (or a return from WaitForExit) to give the DataReceived events time to fire a few more times. I ended up with something like this:

RunningProcess.Start();
RunningProcess.BeginOutputReadLine();
RunningProcess.BeginErrorReadLine();

while (!Completed && !ProcManager.ProcedureAborted)
{
Completed = RunningProcess.WaitForExit(ProcManager.TSK_ABORT_CHECK_TIMEOUT_MS);
}

if (ProcManager.ProcedureAborted)
{
Thread.Sleep(200);
}

200ms seemed to be sufficient in the scenario that I was working on. This approach has potential issues: behavior may be system dependent, and you're making assumptions about how much time you need to flush the buffers (i.e., you might lose output on a slower system, but nothing that you aren't already losing). You may need to play around with it to find a balance between perceivable performance issues caused by too much delay, and not processing all of the output. Again, you could try moving completely to synchronous IO, but the above approach has worked fairly well for me so far.

Hope this helps,

Heath
QuestionByte to bit array problem Pin
gwithey3-Sep-09 4:58
gwithey3-Sep-09 4:58 
AnswerRe: Byte to bit array problem Pin
Henry Minute3-Sep-09 5:24
Henry Minute3-Sep-09 5:24 
GeneralRe: Byte to bit array problem Pin
Luc Pattyn3-Sep-09 5:54
sitebuilderLuc Pattyn3-Sep-09 5:54 
GeneralRe: Byte to bit array problem Pin
Henry Minute3-Sep-09 6:03
Henry Minute3-Sep-09 6:03 
GeneralRe: Byte to bit array problem Pin
Luc Pattyn3-Sep-09 6:23
sitebuilderLuc Pattyn3-Sep-09 6:23 
GeneralRe: Byte to bit array problem Pin
gwithey3-Sep-09 20:47
gwithey3-Sep-09 20:47 
QuestionWhy listview cannot received the OnDragDrop event. Pin
Fired.Fish.Gmail3-Sep-09 4:33
Fired.Fish.Gmail3-Sep-09 4:33 
AnswerRe: Why listview cannot received the OnDragDrop event. Pin
Nuri Ismail3-Sep-09 5:28
Nuri Ismail3-Sep-09 5:28 
GeneralRe: Why listview cannot received the OnDragDrop event. Pin
Fired.Fish.Gmail3-Sep-09 14:57
Fired.Fish.Gmail3-Sep-09 14:57 
GeneralRe: Why listview cannot received the OnDragDrop event. Pin
Nuri Ismail3-Sep-09 21:59
Nuri Ismail3-Sep-09 21:59 
GeneralRe: Why listview cannot received the OnDragDrop event. Pin
Fired.Fish.Gmail4-Sep-09 3:48
Fired.Fish.Gmail4-Sep-09 3:48 
QuestionC# Multilanguage resx Pin
Kaare Tragethon3-Sep-09 4:29
Kaare Tragethon3-Sep-09 4:29 
AnswerRe: C# Multilanguage resx Pin
stancrm3-Sep-09 5:34
stancrm3-Sep-09 5:34 
GeneralRe: C# Multilanguage resx Pin
Kaare Tragethon3-Sep-09 5:50
Kaare Tragethon3-Sep-09 5:50 
QuestionWindowmediaplayer control Pin
Yonathan11113-Sep-09 4:21
professionalYonathan11113-Sep-09 4:21 
AnswerRe: Windowmediaplayer control Pin
Nuri Ismail3-Sep-09 5:09
Nuri Ismail3-Sep-09 5:09 
Questionflexible datagrid Pin
kruegs353-Sep-09 3:10
kruegs353-Sep-09 3:10 

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.