Two methods:
1. Install the service, and then attach vs to the service for debugging.
2. Modify the Program.cs file.
1 namespaceMyproject.service2 {3 Static class Program4 {5 /// <summary>6 ///The main entry point for the application.7 /// </summary>8 Static voidMain ()9 {Ten //servicebase[] ServicesToRun; One //ServicesToRun = new servicebase[] A //{ - //new Opxservice () - //}; the //Servicebase.run (servicestorun); - - //For Debugger -AppDomain.CurrentDomain.UnhandledException + =NewUnhandledexceptioneventhandler (program_unhandledexception); +Opxservice Service =NewOpxservice (); - service. Start (); + } A at /// <summary> - ///Handles The UnhandledException event of the program control. - /// </summary> - /// <param name= "Sender" >The source of the event.</param> - /// <param name= "E" > the<see cref= "UnhandledExceptionEventArgs"/>instance containing the event data.</param> - Static voidProgram_unhandledexception (Objectsender, UnhandledExceptionEventArgs e) in { - Console.WriteLine (e.exceptionobject.tostring ()); to } + } -}
Windows Service Debugging