ServiceController.Refresh(); problems with service and servicecontroller

Posted on 2005-04-18
Last Modified: 2008-01-09
I am using a service controller to start,stop and pause my service. now when i start my service(canpauseandcontinue set to true) i check whether the service is pausable and according enable or disable my pause unpause button. but now the problem is after calling servicecontroller.start() the servicecontroller.status wont update. i tried using servicecontroller.refresh() but still the status wont refresh. but now the funnier part is when i debug, after calling refresh the status is updated. so i m pretty much confused.

also in my service i have set the canpauseandcontinue true, when i try to override the onPause() and onContinue method i get an error that cannot find a suitable onPause and onContinue methods.
Question by:Viraj_Kanwade
    LVL 20

    Accepted Solution

    Do you inherit from ServiceBase? If yes, you should be able to override OnPause and OnContinue even if the service is not set to support pausing.

    I also use the service status and it works fine. But I search for the service every time I need it, like this:

    ServiceController serviceController = null;
    ServiceController[] services = ServiceController.GetServices();
    foreach (ServiceController service in services)
          if (service.ServiceName == serviceName)
                serviceController = service;
    if (serviceController == null)
          this.statusBarServiceStatusPanel.Text = "Service not installed";
          this.statusBarServiceStatusPanel.Text = serviceController.Status.ToString();
    LVL 2

    Author Comment

    heres parts of my codes u can get an idea about the service code

    public class ServiceTest : System.ServiceProcess.ServiceBase
                /// <summary>
                /// Required designer variable.


                static void Main()
                      System.ServiceProcess.ServiceBase[] ServicesToRun;
                      // More than one user Service 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 Service1(), new MySecondUserService()};
                      ServicesToRun = new System.ServiceProcess.ServiceBase[] { new ServiceTest() };

                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                private void InitializeComponent()
                      // ServiceTest
                      this.AutoLog = false;
                      this.CanPauseAndContinue = true;
                      this.ServiceName = "ServiceTest";


                /// <summary>
                /// Pause this service.
                /// </summary>
                protected override void onPause()
                      pause = true;
                      myLog.WriteEntry("Service Paused");

    heres the error i get for using the override in above method
     'servicetest.ServiceTest.onPause()': no suitable method found to override
    LVL 20

    Expert Comment

    Well, it's OnPause, with capital O. Every method in C# starts with a capital letter, it's not like Java

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now