473,382 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Run WinForms app as Console app

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
6 4349
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: andrewcw | last post by:
I have a class with a number of functions. For some form of errors I wanted to use the MessageBox function of Window.Forms. I want to reuse this code in a console application, but now I see I...
7
by: Ori | last post by:
Hi, I would like to create some mechanism to handle all the exceptions which will happen in my application. I have one form which is the base form while all the other forms inherit from it. ...
4
by: Shil | last post by:
Hi, In VC++.Net 2005 visual studio, if I create a new winform drag and drop a button, then double click it to write click event code, then it auto generates the template code for the event in...
2
by: randy1200 | last post by:
I'm working in Visual Studio 2005 and C#. I have a WinForms application with two panels (left panel and right panel). I have a textbox on the left panel, and a button on the right panel. I'd like...
2
by: Oenone | last post by:
I'm writing an application that I'd like to be able to use both as a Windows Forms application, and also as a Console application. If the app is started with no parameters, it should display its...
2
by: Michael D. Ober | last post by:
Is there a way to create a System.Console from code. I periodically have a WinForms app that needs to open a console window for progress tracking. Thanks, Mike Ober.
1
by: Chris | last post by:
Hi Everyone, I have a backup application I'm working on that saves backups with an extension of .ABF. I have figured out how to make the association change with PInvoke/shell32, but would...
8
by: Dilip | last post by:
I am running into a weird problem in my ultra-simple Winforms application written in C#. In the Form.Shown event I set a couple of environment variables using the standard SetEnvironmentVariable...
1
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
We have PCs out on the Manufacturing floor that have public access and are always logged in using a public/global profile. Whenever someone needs to access sensitive information, we want to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.