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?
Any way I can do it inside the existing project so I don't have to migrate stuff?
Jeff
2009-06-01 13:51:46
Right-click the project, go to Properties, and in the form that pops up, change it from a Console app to a WinForms app, close, and recompile.
Chris Doggett
2009-06-01 13:53:53
Thanks Chris, that worked great!
Jeff
2009-06-01 14:04:14
You can also delete the Form class and never instantiate it
Jader Dias
2009-10-04 21:49:03
No- scheduled jobs != windows service. Unless he's using the e-mail to kick off the processing, in which case a service is a better option.
Joel Coehoorn
2009-06-01 13:53:51
Yes, been down that road before. I use to create scheduled jobs using the service infrastructure, but eventually realized doing it that way results in lots of unnecissary code and difficult upgrades. In short, it recreates an infrastructure the task scheduler has provided for free!
Jeff
2009-06-01 14:00:09
+1
A:
It's a hack, but the following blog post describes how you can hide the console window:
http://expsharing.blogspot.com/2008/03/hideshow-console-window-in-net-black.html
Philippe Leybaert
2009-06-01 13:55:45
+6
A:
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
}
MPritch
2009-06-01 13:58:17
+2
A:
Schedule the task to run as a different user than your account and you won't get a window popping up . . .
Wyatt Barnett
2009-06-01 14:06:01