By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,567 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,567 IT Pros & Developers. It's quick & easy.

Run WinForms app as Console app

P: n/a
Joe
We pass args to our WinForms app and would like the console to wait until
the program ends before returning.

For example:
C:MyApp.exe -r something

This returns even though the process is still running (Task manager,
processes).

I would like it to wait until the process is done.

Any ideas?

-Joe
May 21 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Mon, 21 May 2007 10:08:51 -0700, Joe <jb*******@noemail.noemailwrote:
We pass args to our WinForms app and would like the console to wait until
the program ends before returning.
[...]
I would like it to wait until the process is done.

Any ideas?
Compile the application as a console application. You'll still be able to
create forms, but it should act more like a regular console application
otherwise.

Alternatively, make a stub console application that creates your main
application as a new process and then waits for it.

Pete
May 21 '07 #2

P: n/a
Hi Joe,

This has nothing to do with the WinForm application. To wait before a GUI
application returns in command prompt, use "/wait" switch of start command:

C:start /wait notepad.exe
Please note if the path to your application has space, you need to use
following command line:

C:start "foo title" /wait "c:\program files\myapp\myapp.exe" -r something
Hope this helps.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
May 22 '07 #3

P: n/a
Joe
Hi Peter,

I'm going to use your suggestion and create a console app to launch my app.
This will allow the Console.Write to display also.

Thanks,
Joe
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Mon, 21 May 2007 10:08:51 -0700, Joe <jb*******@noemail.noemailwrote:
>We pass args to our WinForms app and would like the console to wait until
the program ends before returning.
[...]
I would like it to wait until the process is done.

Any ideas?

Compile the application as a console application. You'll still be able to
create forms, but it should act more like a regular console application
otherwise.

Alternatively, make a stub console application that creates your main
application as a new process and then waits for it.

Pete

May 22 '07 #4

P: n/a
Joe
I created a simple console app to run my WinForms application but nothing
displays in the console.

proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.Start();
proc.WaitForExit();

If I run my WinForms app MyApp.exe -args >logfile.txt
the file is populated.

Am I doing something wrong?

"Joe" <jb*******@noemail.noemailwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
Hi Peter,

I'm going to use your suggestion and create a console app to launch my
app. This will allow the Console.Write to display also.

Thanks,
Joe
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
>On Mon, 21 May 2007 10:08:51 -0700, Joe <jb*******@noemail.noemail>
wrote:
>>We pass args to our WinForms app and would like the console to wait
until
the program ends before returning.
[...]
I would like it to wait until the process is done.

Any ideas?

Compile the application as a console application. You'll still be able
to create forms, but it should act more like a regular console
application otherwise.

Alternatively, make a stub console application that creates your main
application as a new process and then waits for it.

Pete


May 22 '07 #5

P: n/a
Joe
I got it. I made the following changes:

proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.OutputDataReceived += new
DataReceivedEventHandler(proc_OutputDataReceived);
proc.Start();
proc.BeginOutputReadLine();
proc.WaitForExit();

-Joe

"Joe" <jb*******@noemail.noemailwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I created a simple console app to run my WinForms application but nothing
displays in the console.

proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.Start();
proc.WaitForExit();

If I run my WinForms app MyApp.exe -args >logfile.txt
the file is populated.

Am I doing something wrong?

"Joe" <jb*******@noemail.noemailwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
>Hi Peter,

I'm going to use your suggestion and create a console app to launch my
app. This will allow the Console.Write to display also.

Thanks,
Joe
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
>>On Mon, 21 May 2007 10:08:51 -0700, Joe <jb*******@noemail.noemail>
wrote:

We pass args to our WinForms app and would like the console to wait
until
the program ends before returning.
[...]
I would like it to wait until the process is done.

Any ideas?

Compile the application as a console application. You'll still be able
to create forms, but it should act more like a regular console
application otherwise.

Alternatively, make a stub console application that creates your main
application as a new process and then waits for it.

Pete



May 22 '07 #6

P: n/a
On Tue, 22 May 2007 07:06:35 -0700, Joe <jb*******@noemail.noemailwrote:
I created a simple console app to run my WinForms application but nothing
displays in the console.
I see from your other post that you managed to get this block of code to
do something akin to what you wanted. Whether it's exactly what you
wanted, I don't know. You shouldn't be setting the "RedirectStandard..."
properties unless you really want to get access to those streams
internally. If that's really what you want to do, then adding code to
actually get the redirected output is the right fix. However, if you only
added that code just to get the thing to work, then the right fix is to
stop setting the "RedirectStandard..." properties to true.

And of course, I neglected to mention in my first reply that if it's
suitable to use the "start" command with the "/wait" switch, that's an
even easier mechanism to do what you want. Fortunately, someone else did
bring that up.

Pete
May 22 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.