如何在 protected void 中调用 public void

how to call public void in protected void

我有这段代码想调用Button1_click请帮助我。

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 {  } 
}

您可以直接调用方法:

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

您必须确保使用您的值填充参数 serviceName 和 Timeout。