|
Luc Pattyn, thank you very much!
That was very useful!
But, unfortunately, replacing \n by \n\r didn`t do the trick!
Besides, with a real-world app, I won`t have an opportunity to do that!
Because, the app which out I want to redirect, was written not by me,
and I don`t have its source code!
Please, can you provide me with a source code example,
which will use a thread with a loop, and reading arbitrary strings?
I didn`t understand this solution!
Thanks!
|
|
|
|
|
This is a first draft, I did not test it:
bool stdReading;
StreamReader stdout;
StreamReader stderr;
public void LaunchProcess() {
ProcessStartInfo psi=new ProcessStartInfo();
psi....
log("Starting process");
Process p=Process.Start(psi);
stdout=p.StandardOutput;
stderr=p.StandardError;
stdReading=true;
Thread outThread=new Thread(new ThreadStart(outReader));
outThread.Start();
Thread errThread=new Thread(new ThreadStart(errReader));
errThread.Start();
p.WaitForExit();
log("Process is done");
Thread.Sleep(300);
stdReading=false;
errThread.Join(300);
outThread.Join(300);
log("Reading streams in done");
}
public void outReader() {
int DIM=1024;
char[] buf=new char[DIM];
while (stdReading) {
int count=stdout.Read(buf, 0, DIM);
string s=new string(buf, 0, count);
...
}
}
public void errReader() {
int DIM=1024;
char[] buf=new char[DIM];
while (stdReading) {
int count=stdout.Read(buf, 0, DIM);
string s=new string(buf, 0, count);
...
}
}
Notes:
1. you may want to decrease DIM to get the output sooner when lines are short;
2. you may want to set Thread.IsBackground true so the threads don't prevent app termination.
|
|
|
|
|
Now I understood!
It Seems to work!!!
This is the magic solution!!!!
Luc Pattyn, thanks!
Thank you very much for all your help!!!
|
|
|
|
|
you're welcome.
|
|
|
|
|
|
Figured out, that if a native win32 console application
didn`t fflush its stdout and stderr,
redirecting its output is a real problem!
Is it possible to redirect 'bad' console apps,
(without fflush(stdout))?
Also found solution, by _Olivier_, but I don`t want to use
any stubs an 'between stuff'!
Real-Time Console Output Redirection[^]
Thank you all, for your help!
|
|
|
|
|
public class MyTextBox : TextBox
{
private static Dictionary<IntPtr, WeakReference> mList = new Dictionary<IntPtr, WeakReference>();
public MyTextBox()
{
mList.Add(Handle, new WeakReference(this));
}
}
Any problem for MyTextBox being garbage collected?
|
|
|
|
|
I recommend that you google ".net weak references". You'll get over 6.8 million results back, and there appear to be a number of good links on the first page of results.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
If nothing has a strong reference to MyTextBox, then yeah, it could get GC'ed. Thats why its called a WeakReference. Why would you use a WeakReference here anyways?
|
|
|
|
|
Making it weak reference will not prevent GC to play it's role. It's static. If it's not weak reference strong references of hundreds of textboxes in my app get polluted. I just bother with the textboxes that are really alive.
|
|
|
|
|
If you're relying on the reference being there, then you either need something that can recreate the reference when needed, or you need to maintain a strong reference.
|
|
|
|
|
I just bother with the textboxes that are really alive.
|
|
|
|
|
Objects of type MyTextBox will be collected if there are no strong references to them and, of course, the GC performs a garbage collection. mList dictionary will not be collected becouse there is a static strong reference to it, unless you clear this reference. I guess you have a static method or property to access the contents of mList Dictionary, becouse if you don't this dictionary is completely useless, and I don't see how you should need it unless MyTextBox class was much more heavy than it seems to be.
|
|
|
|
|
thomus07 wrote: private static Dictionary<intptr, weakreference="">
What do you think is going to happen with that IntPtr when the GC collects the TextBox?
|
|
|
|
|
How to extract any object from the image after convert it's to black and white.
|
|
|
|
|
If the image is of a top hat I might be able to extract a rabbit from it, otherwise it beyond my abilities.
|
|
|
|
|
Boom tish!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
a
Ramkumar
("When you build bridges you can keep crossing them. ")
http://ramkumarishere.blogspot.com
|
|
|
|
|
Ramkumar_S wrote: a
aa
|
|
|
|
|
|
Were you proposing to post a reply, with each letter in a separate message?
If so, this could take a while...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
So you think being abrupt and rude will get you an answer? Good luck with that.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
What is the difference between an orange?
|
|
|
|
|
DAMN YOU! You beat me to it! (But I still have to give you a 5.)
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|