0
我有這段代碼,我想調用Button1_click請幫助我。如何調用public void protected void
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 { }
}
你需要2個值'serviceName'和'timeoutMilliseconds' – fubo
基本上@fubo試圖告訴你,你可以這樣調用它:'RestartService(「somestring」,999);'。假設兩個方法在同一個類中。雖然我想知道爲什麼在那裏有一個catch(在代碼的最後)? –