JohnH said:
Does any one now how to create a .net service thet when run from the
command
line with say a -D argument will run as a console app and be able to
output
to that console window. The same .exe would start as a normal service
wihout
the -D argument and require use of the NET START command or other.
This may be enough to get you started. This would allow a service to start
up as a form as well. This is a lot easier to debug than attaching to a
running service, especially for the startup code. Haven't tried the console
one but have often used the WinForm one during development of services.
// Choose one or none.
//#define FORM
#define CONSOLE
public static void Main(string[] Args) {
#if FORM
// Service running as a form.
MyService Service = new MyService();
Service.OnStart(Args);
System.Windows.Forms.Application.Run(new
System.Windows.Forms.Form());
Service.OnStop();
#elseif CONSOLE
// Service running in the console.
MyService Service = new MyService();
Service.OnStart(Args);
// Presumably OnStart() has initialized _Stop and spun off a worker
thread or something.
while (!_Stop) Sleep(10);
Service.OnStop();
#else
// Normal service.
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] {new
MyService()};
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
#endif
return;
}
-- Alan