I have a console application I'm using to run scheduled jobs through windows scheduler. All the communication to/from the application is in email, event logging, database logs. Is there any way I can suppress the console window from coming up?
If you do not know what I am talking about: press Win+R, type “help” and press ENTER. A black console window will open, execute the HELP command and close again. Often, this is not desired. Instead, the command should execute without any visible window.
You can use Environment. Exit(0) and Application. Exit .
Console applications are designed to be used from a "text-only" interface, or run without any interface by another automated tool.
Sure. Build it as a winforms app and never show your form.
Just be careful, because then it's not really a console app anymore, and there are some environments where you won't be able to use it.
Borrowed from MSDN (link text):
using System.Runtime.InteropServices; ... [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName,string lpWindowName); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); ... //Sometimes System.Windows.Forms.Application.ExecutablePath works for the caption depending on the system you are running under. IntPtr hWnd = FindWindow(null, "Your console windows caption"); //put your console window caption here if(hWnd != IntPtr.Zero) { //Hide the window ShowWindow(hWnd, 0); // 0 = SW_HIDE } if(hWnd != IntPtr.Zero) { //Show window again ShowWindow(hWnd, 1); //1 = SW_SHOWNORMA }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With