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

Command Line Execution

P: 3
I have a program in C#.NET which runs in both GUI and command line mode. When I pass the command line arguments to the executable like:

C:\>myprogram.exe -a file.txt the program is invoked, processes the file and performs a long process. In the meantime the command prompt appears in the command window and it can accept new commands.

I would like to hold the command prompt (prevent it from accepting new commands) till myprogram.exe completes execution.

Suggestions?
Jan 25 '09 #1
Share this Question
Share on Google+
5 Replies


vekipeki
Expert 100+
P: 229
If you change your application's type to Console Application, it will block the prompt when started, but you can still use Windows Forms.

But then a command prompt window will show on every app start, since (I think) you cannot know if the user started you app using a win shortcut or from a command prompt.
Jan 26 '09 #2

P: 3
Thanks Vek!
The idea is to run the process through multiple batch commands but sequentially. Converting to a console app will address the issue but the extra console screen might not be acceptable when the application is run in GUI mode. Is there anyway to suppress the console screen.
Jan 26 '09 #3

Plater
Expert 5K+
P: 7,872
Subscribing. (Because I have long tried to figure this out as well)
Jan 26 '09 #4

vekipeki
Expert 100+
P: 229
There are two or three things you could do (that I know of).

You can make a Console app which would serve as a "loader"; if you pass arguments, then it starts a new WinForms process and closes itself, otherwise it does the processing and blocks the prompt until finished.

There are also ways to hide the Console window (check this link for example: Hide Console Window in Console Application In C#.Net DotNet Friends) once the app is started, but a Console window will appear quickly anyway.

There is also sort of a "hack" that looks like it might work (haven't tested it): How To Create a Console/Window Hybrid Application in C# by Jeffrey Knight. The idea is to create a WinForms app, and then, if you want to block the console, check if the foreground window is actually a Console window and attach to that thread using some Kernel32 calls.

I think these are all you options - if you really want to have a (what he calls a) "hybrid" app.
Jan 27 '09 #5

P: 3
I tested the "hack". Doesn't work the way I need.
Hiding console is not a smooth solution as it always has some flickering seen in GUI mode till the console window is found and hidden.
I think the best approach is making a "Loader" app. Have not tested it yet how it will behave after invoking the GUI but if it works, the solution will be smooth.
Jan 28 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.