When I start my application I need to check if one of my service is running. If service is not running then I have to allow the user to start the service and then execution continues. If User chooses not to start the service then I have to Exit the Application. For every 10 sec I have to pop up the message to start the service,during this time program execution should not continue.Below is the code I have written. The service which I am looking to be running has a event handler which notifies when service is available(event handler is WindowsServiceAvailableEventHandler).
I have two questions here
- How to resume or interrupt the Thread which is sleeping(Thread.Sleep(10000);) as soon as ServiceAvailable Event is raised?
- When user want to start the service then he will click on Yes button and Dailog Box Closes and user will not know if something is happening..so I am looking for something like progress bar which will tell user that it is waiting for the user to start the service...as soon as service is started progress bar should close.How to achieve this?
My code:
this.windowsService.ServiceAvailable += this.WindowsServiceAvailableEventHandler
While (!CheckifServiceStarted())
{
DialogResult dlgResult = MessageBox.Show("Service is not Started.Please start Service to continue", "Start Service", MessageBoxButtons.YesNo);
if (dlgResult == DialogResult.Yes)
{
Thread.Sleep(10000);
}
else
{
System.Environment.Exit(0);
}
}
private void DataServicesAvailableEventHandler(object sender, EventArgs e)
{
//How to Resume or Interrupt the Thread here?
}