|
I am trying to create a child process and listen to it and talk to it.
I am using what I think is the standard model: I create the process with "UseShellExecute" set to false, and use a streamwriter and a streamreader to read and write.
The child process writes some data to the console (redirected to me), then waits for me to write back. If I don't write back, it sits there forever.
The problem I am having is that sometimes it writes a few K bytes of stuff at once. When it does this, the last few lines do not get written, and so I sit there forever in my process, waiting for the rest of the stuff to be written.
If it writes smaller amounts of stuff at one time, it seems to work fine. I only have problems when it starts writing lots of stuff pretty quickly.
The child process runs in other cases where it is called from processes (non-C# apps), and I am certain that I am doing a "fflush(stdout)" after ever write in there anyway (the child process is written in C, and it does all of its writing through one function, which has a "fflush(stdout)").
All of the reading is taking place inside a thread, but I don't think this is the problem because (apparently) nothing outside of the thread is touching the streamreader.
I'm at the point where I'm wondering if this is a known bug in streamreader? Does it barf if its buffer fills up?
Anyone have any ideas about how to do a workaround?
Thank you,
bruce
|
|
|
|
|
Are you trying to read standard error too? MSDN[^] says that this can be problematic, unless you're reading standard output and standard error on different threads.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
No, but thank you for the reply.
It's very simple. The thread sits there and does "ReadLine" from the stream buffer. When it gets a line, writes it to the console, and loops.
The stuff comes in pretty fast, but eventually the program will hang. If I enter the debugger, it's waiting for input, and if I drill down into the stream buffer, the buffer is full and the last thing I see displayed on the screen is the last thing in the buffer.
I am probably wrong, but here goes. I can imagine that most uses of this are done in one of two ways:
1) Continuous input.
2) Small hunks of input, which are fully processed and therefore never fill the buffer.
What I have is bursts of input, and then the child process will sit there and do nothing for a while. It would seem like a stream buffer should be used commonly enough that it should work correctly, but perhaps this way of doing input is rare.
If the stream buffer were my code, I'd assume I had a bug in the "block if buffer full" logic.
Thank you,
bruce
|
|
|
|
|
I have two forms:
Form1 - loads as startup form.
Form2 = Loads when I push a button on Form1
I set the BorderStyle of Form2 as a FixedToolWindow via code AND properties grid.
I set the height and width via code AND properties grid. The height is 528, and the width is 886.
Again, I set this twice. 1) in code on the Form Load. 2) in the properties grid
When I click the button on Form1 to launch Form2 it shows up full screen.
I have the StartPosition set to 'CenterScreen' and WindowState to 'Normal'
I also tried setting the height and width of Form2 after I created a new instance of it:
Form2 frm2 = new Form2()
frm2.height = 528;
frm2.width = 886;
frm2.Show();
Still goes full screen.
But, another twist. It only does it once. Like the first time I load the app and launch it this is what happens. If I close form2 and open it back up without closing the whole application, works fine.
Any suggestions?
Steve Welborn
Software Architect
|
|
|
|
|
Swelborn wrote:
Form2 frm2 = new Form2()
frm2.height = 528;
frm2.width = 886;
frm2.Show();
Can't work. The Show method causes the initialisation/load methods to be called, which will set the size. You need to set the size within the form, or after you show it. The nicest way would be to pass the desired size in the constructor, and use them when the form is first shown.
Swelborn wrote:
But, another twist. It only does it once. Like the first time I load the app and launch it this is what happens. If I close form2 and open it back up without closing the whole application, works fine.
Amusingly, when you create this form after the first time, .NET has already cached it, when you closed it last time, it was just hidden, so this init code will not be called again, instead the framework just shows the form that it was hiding when you tell it to.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks Christian for the info. I will place the information in the constructor and see what that does.
Steve Welborn
Software Architect
|
|
|
|
|
Hi
I need to a Form that accepts dropping files that are dragged from Windows Explorer and somehow handle the event when the file is dropped. Just like for example MS Word or IE accept dropping files and they open them.
How to do this? Thanks in advance , H.
|
|
|
|
|
Forget it, I already figured that out myself .
H.
|
|
|
|
|
for others who may want to know how to do it Drag files from explore work like similar way the other drag and drop work except you check that the draged item format is DataFormats.FileDrop by using GetDataPresent
and handle the files in drop handler after convert them to array of string some thing like string[] fileNames= (string[])e.Data.GetData(DataFormats.FileDrop);
MCAD
-- modified at 18:56 Monday 12th September, 2005
|
|
|
|
|
I get an exception when trying to read in my XML document, which is the settings for my serial port. The error is this:
There is an error in XML document(2, 2)
<CommBaseSettings xmlns="> was not expected
Here is a snippet of the xml document
<?xml version="1.0"?>
<CommBaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<port>COM3</port>
<baudRate>2400</baudRate>
<parity>none</parity>
Can someone help me out in inderstanding what is going on here?
Thanks
FYI I'm using a class called CommBase from MS that some dude wrote up in an MSDN mag some years ago. Soe far it works great, just getting the settings to read in. Saves them just fine.
Thanks
Tom Wright
tawright915@yahoo.com
-- modified at 17:37 Monday 12th September, 2005
|
|
|
|
|
Does the file open up correctly in Internet Explorer without any errors?
<?xml version="1.0"?>
<CommBaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<port>COM3</port>
<baudRate>2400</baudRate>
<parity>none</parity>
</CommBaseSettings>
seems to open up correctly.
Regards
Senthil
_____________________________
<font face="Verdana" size=1><a href="http://blogs.wdevs.com/senthilkumar">My Blog</a> | <a href = "http://www.codeproject.com/script/articles/list_articles.asp?userid=492196">My Articles</a> | <a href = "http://geocities.com/win_macro">WinMacro</a></font>
|
|
|
|
|
Hi
I have a status bar in my main form. This status bar displays different text. I need to display a tooltip with a text (on mouse over) if the text is too large to fit into the status bar - if it's not completely visible (similar functionality as in Visual Studio). How do I determine if the length of the text string is larger than the current width of the status bar panel? Currently I'm using, e.Graphics.MeasureString, to compare length of the string in pixels to the length of the status bar panel in pixels, but that hasn't been giving me the the results I wanted.
Thank you in advance
-- modified at 16:58 Monday 12th September, 2005
|
|
|
|
|
Hi, im moving a .xls file to another directory, but if this file exists i want to rename it and still move it. For example, if i have a ex.xls in a directory and im trying to move another file with the same name, i want to rename it like to ex1.xls and move it. How can i do this? any ideas?
Thanks in advance.
|
|
|
|
|
|
a simple function as such should do the trick.
void MoveMe(string filename)
{
int x = 1;
string newfile = filename;
while(System.IO.File.Exists(newfile) == true)
{
String[] tmp = filename.Split(Convert.ToChar("."));
newfile = tmp[0] + x + "." + tmp[1];
x++;
}
System.IO.File.Move(filename, newfile);
}
-- modified at 13:45 Monday 12th September, 2005
|
|
|
|
|
do the variables filename and newfile includes the directory?
|
|
|
|
|
in this case, yes. The file name is split at the "." in the filename.
So if filename = C:\Autoexec.bat then newfile = c:\Autoexec1.bat
Because of design, if a file name consists of more than one period, you will receive unexpected results.
|
|
|
|
|
Hello all
I am starting a mailer application project in c# using Visual Studio .Net. As I need to learn more about the process of sending emails (e.g email message structures, SMTP Protocol etc.) , I would appreciate it if you could send a few links to relevant reading material and examples.
And equally important - I need to know which classes and assemblies deal with sending email messages (I saw something about microsoft.uddi.dll in the Visual Studio help).
Will appreciate any help,
Thanks,
Gal
|
|
|
|
|
|
That's great, it will really help me get started.
Thanks a lot.
Gal
|
|
|
|
|
Hi,
I would like to build an application for both smartphones and pdas running windows mobile 2003 or 2005. what is the best practice to develop such application?
regards,
rnv
|
|
|
|
|
|
In the C# books I've read, drawing objects such as pens, brushes, etc are usually created in a using declaration in OnPaint(). I don't see anything wrong with this as it seems to be more resource friendly but I've heard others say these objects should be cached, such as storing them as instance fields. Are there any guidelines for going one way versus the other?
|
|
|
|
|
The only guidelines I can suggest are:
1) How many times a second are you going to repaint your form? If your writting an analog clock that repaints itself every 50 milliseconds, you'll want to create your pens and brushes once and cache them so you're not creating and destroying them a couple hundreds times per second. If you only repaint the form when Windows tell you to, then you could probably get away with creating and destorying your pens and stuff on demand.
2) If you're painting alot of static stuff. In the clock example, the clock face and hands don't change between any repaints. Just the positions of certain items change. In this case you could get away with caching your drawing objects. If you're painting dynamic data that frequently changes the colors of what your drawing between repaints, then you'll have to create and destroy your drawing objects on demand.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks Dave,
Those are some good examples of when caching might be useful.
|
|
|
|