[RESOLVED] Debug a Windows Service by running in locally
I found once how to do this and it was a lifesaver. Now I can't remember which program has the code and I can no longer find on the Internet what I am looking for and have it work.
I thought it was this:
Code:
// The main entry point for the process
static void Main()
{
#if (!DEBUG)
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
#else
// Debug code: this allows the process to run as a non-service.
// It will kick off the service start point, but never kill it.
// Shut down the debugger to exit
Service1 service = new Service1(); service.<Your Service's Primary Method Here>();
// Put a breakpoint on the following line to always catch
// your service when it has finished its work
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#endif
}
But I don't know what to change the bold-face line to.
This is my code in the !debug path:
Code:
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new ReceiveShippingFile()
};
ServiceBase.Run(ServicesToRun);
But when I try to put this in my debug path,
Code:
// Debug code: this allows the process to run as a non-service.
// It will kick off the service start point, but never kill it.
// Shut down the debugger to exit
ReceiveShippingFile myService = new ReceiveShippingFile();
myService.
I don't get any methods displayed by intellisense after I type myService-dot.
Re: Debug a Windows Service by running in locally
I'm sorry I posted this. I tried basically the same thing again,
Code:
//ServiceBase[] ServicesToRun;
//ServicesToRun = new ServiceBase[]
//{
// new ReceiveShippingFile()
//};
//ServiceBase.Run(ServicesToRun);
ReceiveShippingFile service = new ReceiveShippingFile();
service.ProcessShippingFile("");
// Put a breakpoint on the following line to always catch
// your service when it has finished its work
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
and it is fine now. I guess it just took an erase and a retry.