Bind Label in Windows Form with ServiceController.Status

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Bind Label in Windows Form with ServiceController.Status



I'm trying to implement UI (Windows Form) to manage a service like installing , uninstalling , stop , restart .. so on.
I want to inform the user about the current status of the service but I'm doing this hard coded like when i stop the service i change the label's text to "Stopped".


if (this.serviceController.Status == ServiceControllerStatus.Stopped)

try

this.serviceController.Start();

catch (Exception ex)

Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);


statusvallbl.Text = "Running...";



But i don't want it to be like that , i want to bind the serviceController.Status.ToString() value to the status label so if it changes , it would notify the UI.
I read about binding value to control by implementing INotifyPropertyChanged and using Control.DataBindings but still how can i make changes to the ServiceController Class.



#Update 1



Ok I used ServiceController.WaitForStatus() but still it freezes the UI for about 3 seconds everytime i try to start the Service which is verrrrry bad UX. Any suggestions please??
This is after the change


if (this.serviceController.Status == ServiceControllerStatus.Stopped)

try

this.serviceController.Start();

catch (Exception ex)

Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);


statusvallbl.Text = "Starting...";
this.serviceController.WaitForStatus(ServiceControllerStatus.Running);
statusvallbl.Text = "Running...";









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered