Have you ever need to debug a windows service??
Here is a way ..The onl thing is put this code at  program's start line
 #if (!DEBUG)
            ServiceBase[] ServicesToRun;
 
            // More than one user WindowsService_tmp 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 MailService(), new MySecondUserService()};
            //
            ServicesToRun = new ServiceBase[] { new Service1() };
 
            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.OnStart(new string[] { ""});
            // 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
No comments:
Post a Comment