Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ServiceController.Refresh(); problems with service and servicecontroller

Posted on 2005-04-18
3
Medium Priority
?
703 Views
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.
0
Comment
Question by:Viraj_Kanwade
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 300 total points
ID: 13813273
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;
            break;
      }
            
if (serviceController == null)
      this.statusBarServiceStatusPanel.Text = "Service not installed";
else
      this.statusBarServiceStatusPanel.Text = serviceController.Status.ToString();
0
 
LVL 2

Author Comment

by:Viraj_Kanwade
ID: 13813526
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
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 13813607
Well, it's OnPause, with capital O. Every method in C# starts with a capital letter, it's not like Java
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

575 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