Results 1 to 2 of 2

Thread: [RESOLVED] Debug a Windows Service by running in locally

  1. #1
    PowerPoster MMock's Avatar
    Join Date
    Apr 07
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,214

    Resolved [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.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    PowerPoster MMock's Avatar
    Join Date
    Apr 07
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,214

    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.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •