Naitik dave
Naitik dave

Reputation: 3

how to call public void in protected void

I have this code which I want to call in Button1_click pls help me.

protected void Button1_Click(object sender, EventArgs e)
{

}
public static void RestartService(string serviceName, int timeoutMilliseconds) 
{
    ServiceController service = new ServiceController(serviceName); 
    try { int millisec1 = Environment.TickCount; 
    TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
    service.Stop();      
    service.WaitForStatus(ServiceControllerStatus.Stopped, timeout); 
    // count the rest of the timeout 
    int millisec2 = Environment.TickCount;
    timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds - (millisec2-millisec1)); 
    service.Start(); service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch {  } 
}

Upvotes: 0

Views: 526

Answers (1)

Sebi
Sebi

Reputation: 3979

You can just call the Method:

protected void Button1_Click(object sender, EventArgs e)
{
   RestartService("serviceName", 3000);
}

You have to fill the parameter serviceName and Timeout with your values for sure.

Upvotes: 1

Related Questions