Change the static Main method in your service app to something like this:
// The main entry point for the process
// add the string[] args as a parameter
static void Main(string[] args)
{
if ((args.Length > 0) && ("/?" == args[0]))
{
MessageBox.Show("" + "Usage: DELL_QWatcher [/?] [/debug]\n" + "\n" + "/?
Displays this help dialog.\n" + "\n" + "/debug Service as an application
rather", "DELL QWatcher Object");
} else if ((args.Length > 0) && ("/debug" == args[0].ToLower()))
{
// main service object
DELL_QWatcher oWatcher = new DELL_QWatcher();
oWatcher.OnStart(new string[1]);
Application.Run();
oWatcher.OnStop();
} else
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
DELL_QWatcher() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
// this is the normal service code generated by the IDE
// ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
// ServicesToRun = new ServiceBase[] { new DELL_QWatcher() };
// ServiceBase.Run(ServicesToRun);
}
I'm trying to create a Windows service which can also be run as a
console app if it is started with some switch (eg -console). Is there
any way to do this?
Previously (in VC6) it's just been a matter of using the executable for
my service and run it from the command prompt. What's the equivalent to
this in C#?
TIA,
Håvard