Saturday, February 19, 2011

Service.Controller Status / Polling

I'm having a problem with a administrative app I'm working on. I'm build an interface for stopping, starting and querying various services across 40 or so servers.

I'm looking at service.controller and have been successful in stopping and starting various services with button events but now I'm trying to figure out a way to return the service status to a text box and query for service status every 10 seconds or so and I feel like I'm hitting a brick wall.

Does anyone have any tips or insight?

Thanks!!

From stackoverflow
  • You can trigger the periodic service check by using a Timer object. You can run your service queries on the Elapsed event.

        private void t_Elapsed(object sender, ElapsedEventArgs e)
        {
            // Check service statuses
        }
    

    As for displaying statuses in a text box, you should be able to use the ToString() method on the service status and display that in a regular text box. Remember that you may or may not be on the GUI thread when reacting to the timer events, so you'll need to invoke yourself on to the main thread.

        private delegate void TextUpdateHandler(string updatedText);
    
        private void UpdateServerStatuses(string statuses)
        {
            if (this.InvokeRequired)
            {
                TextUpdateHandler update = new TextUpdateHandler(this.UpdateServerStatuses);
                this.BeginInvoke(update, statuses);
            }
            else
            {
                // load textbox here
            }
        }
    

0 comments:

Post a Comment