473,773 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4362
On Mon, 21 May 2007 10:08:51 -0700, Joe <jb*******@noem ail.noemailwrot e:
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\mya pp.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*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Mon, 21 May 2007 10:08:51 -0700, Joe <jb*******@noem ail.noemailwrot e:
>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. RedirectStandar dOutput = true;
proc.StartInfo. RedirectStandar dError = true;
proc.Start();
proc.WaitForExi t();

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

Am I doing something wrong?

"Joe" <jb*******@noem ail.noemailwrot e in message
news:%2******** **********@TK2M SFTNGP05.phx.gb l...
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*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
>On Mon, 21 May 2007 10:08:51 -0700, Joe <jb*******@noem ail.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.

Alternativel y, 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. RedirectStandar dOutput = true;
proc.StartInfo. RedirectStandar dError = true;
proc.OutputData Received += new
DataReceivedEve ntHandler(proc_ OutputDataRecei ved);
proc.Start();
proc.BeginOutpu tReadLine();
proc.WaitForExi t();

-Joe

"Joe" <jb*******@noem ail.noemailwrot e in message
news:%2******** ********@TK2MSF TNGP05.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. RedirectStandar dOutput = true;
proc.StartInfo. RedirectStandar dError = true;
proc.Start();
proc.WaitForExi t();

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

Am I doing something wrong?

"Joe" <jb*******@noem ail.noemailwrot e in message
news:%2******** **********@TK2M SFTNGP05.phx.gb l...
>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*********@nn owslpianmk.comw rote in message
news:op******* ********@petes-computer.local. ..
>>On Mon, 21 May 2007 10:08:51 -0700, Joe <jb*******@noem ail.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*******@noem ail.noemailwrot e:
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 "RedirectStanda rd..."
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 "RedirectStanda rd..." 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
1506
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 would have to remove all the MessageBox calls for error messages and return the errors. Is there a way to include that functionality in a console applic. I am just doing the classes in console to save a bit of time.
7
17757
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. I try to find a way to "register" the base form to the Error handling , but I don't know how….
4
3076
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 Form1.h file rather than Form1.cpp file. This behaviour is against standard C++ coding standards, where my header file is supposed to just have declarations. I read in other topics that this is due to C# association of single file concept with the...
2
2516
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 to have a button-press from the right panel call a function in the left panel, which might simply Console.Writeline(textBox1.Text); If I could get the instance of the PanelLeft class, I could simply say: ...
2
1787
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 window and allow the user to interact with it. If parameters are provided, it should instead run as a console application and should output various information to the standard output channel (so that the output can be redirected if required). ...
2
1638
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
1867
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 like some advice on how to handle the file passed as an arguement to my WinForms application. I was thinking about changing the application to a console application with
8
2808
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 API like so: Environment.SetEnvironmentVariable("someKey", somevalue, EnvironmentVariableTarget.User); I have 2 such calls. Amazingly it takes nearly 10 seconds for these
1
5231
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 verify they have permission by checking their username/password on our Active Directory server. How should I authenticate our users using a local Active Directory server? I have tried the code below, but it returned a COMException 0x80005000...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.