Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3724282
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:35:04+00:00 2026-05-19T06:35:04+00:00

My app has a UserControl that wraps a ServiceController to expose start/stop/restart win service

  • 0

My app has a UserControl that wraps a ServiceController to expose start/stop/restart win service functionality to the user. My concern at the moment is restarting. It takes a small amount of time and I want to reflect the restarting status inside of the control. This is roughly what I have for the restart button click handler

private void RestartButton_Click(object sender, RoutedEventArgs e)
{
    startStopButton.Visibility = Visibility.Hidden;
    restartButton.Visibility   = Visibility.Hidden;
    statusTextBlock.Text = "Restarting...";

    Controller.Stop();
    Controller.WaitForStatus(ServiceControllerStatus.Stopped);
    Controller.Start();
    Controller.WaitForStatus(ServiceControllerStatus.Running);

    startStopButton.Visibility = Visibility.Visible;
    restartButton.Visibility   = Visibility.Visible;

    statusTextBlock.Text = Controller.Status.ToString();
}

Even when I step through the debugger I don’t see these changes reflected in the application. Must be something that I’m missing. Also, I’ve tried disabling the buttons instead of hiding them and that does not work either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T06:35:05+00:00Added an answer on May 19, 2026 at 6:35 am

    You’re doing everything on the UI thread, so the UI isn’t updated until this code completes. You should do the heavy lifting on a background thread. The BackgroundWorker component makes this easy:

    private void RestartButton_Click(object sender, RoutedEventArgs e)
    {
        startStopButton.Visibility = Visibility.Hidden;
        restartButton.Visibility   = Visibility.Hidden;
        statusTextBlock.Text = "Restarting...";
    
        var backgroundWorker = new BackgroundWorker();
    
        // this delegate will run on a background thread
        backgroundWorker.DoWork += delegate
        {
            Controller.Stop();
            Controller.WaitForStatus(ServiceControllerStatus.Stopped);
            Controller.Start();
            Controller.WaitForStatus(ServiceControllerStatus.Running);
        };
    
        // this delegate will run on the UI thread once the work is complete
        backgroundWorker.RunWorkerCompleted += delegate
        {
            startStopButton.Visibility = Visibility.Visible;
            restartButton.Visibility   = Visibility.Visible;
    
            statusTextBlock.Text = Controller.Status.ToString();
        };
    
        backgroundWorker.RunWorkerAsync();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a winforms app that uses a UserControl. The user control's job is
I've got WPF 4 app that has a number of UserControls that share styles
My app has several buttons which trigger different events. The user should NOT be
My app has a session timeout after 30 minutes. If the user has a
My app has some table cells that vary in height. The cells can also
I have a Windows Forms app, that has a single ElementHost containing a WPF
A WPF app has an operation of loading a user control from a separate
I have built a User Control library that has a reference to a WCF
Hopefully I am stating that right. I have a WinForm(3.5) app that has 1
My app has a notification service. The problem is when my app has been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.