Link to home
Start Free TrialLog in
Avatar of Viraj_Kanwade
Viraj_KanwadeFlag for India

asked on

ServiceController.Refresh(); problems with service and servicecontroller

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.
ASKER CERTIFIED SOLUTION
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Viraj_Kanwade

ASKER

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() };

                  System.ServiceProcess.ServiceBase.Run(ServicesToRun);
            }
---------------------------------
            /// <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
ERROR::::
 'servicetest.ServiceTest.onPause()': no suitable method found to override
Well, it's OnPause, with capital O. Every method in C# starts with a capital letter, it's not like Java