本文整理汇总了C#中System.ServiceProcess.ServiceController.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceController.Stop方法的具体用法?C# ServiceController.Stop怎么用?C# ServiceController.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceProcess.ServiceController
的用法示例。
在下文中一共展示了ServiceController.Stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RestartSB
public static void RestartSB()
{
string ServiceName = "SolutionBuilder Core Service";
ServiceController service = new ServiceController();
service.MachineName = ".";
service.ServiceName = ServiceName;
string status = service.Status.ToString();
try
{
if (service.Status == ServiceControllerStatus.Running)
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
}
//Recycle App Pool
try
{
RecycleAppPool();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
if (service.Status == ServiceControllerStatus.Stopped)
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
示例2: runServiceCheck
public void runServiceCheck()
{
Utils util = new Utils();
ServiceController sc = null;
try
{
sc = new ServiceController(serviceName);
switch (sc.Status)
{
case ServiceControllerStatus.Running:
break;
case ServiceControllerStatus.Stopped:
sc.Start();
util.writeToLogFile("service checker starting "+serviceName);
break;
case ServiceControllerStatus.Paused:
sc.Stop();
sc.Start();
util.writeToLogFile("service checker starting " + serviceName);
break;
case ServiceControllerStatus.StopPending:
sc.Stop();
sc.Start();
util.writeToLogFile("service checker starting " + serviceName);
break;
case ServiceControllerStatus.StartPending:
sc.Stop();
sc.Start();
util.writeToLogFile("service checker starting " + serviceName);
break;
default:
break;
}
}
catch (Exception e)
{
util.writeEventLog(e.Message);
util.writeEventLog(e.StackTrace);
}
finally
{
try
{
if (sc != null) sc.Close();
} catch (Exception) {}
}
}
示例3: RestartSmartComService
/// <summary>
/// Перезапустить службу SmartCOM.
/// </summary>
/// <param name="timeout">Ограничение по времени для перезапуска службы SmartCOM.</param>
public static void RestartSmartComService(TimeSpan timeout)
{
var service = new ServiceController("SmartCom2");
var msStarting = Environment.TickCount;
var waitIndefinitely = timeout == TimeSpan.Zero;
if (service.CanStop)
{
//this.AddDebugLog(LocalizedStrings.Str1891);
service.Stop();
}
if (waitIndefinitely)
service.WaitForStatus(ServiceControllerStatus.Stopped);
else
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
//this.AddDebugLog(LocalizedStrings.Str1892);
var msStarted = Environment.TickCount;
timeout = timeout - TimeSpan.FromMilliseconds((msStarted - msStarting));
//this.AddDebugLog(LocalizedStrings.Str1893);
service.Start();
if (waitIndefinitely)
service.WaitForStatus(ServiceControllerStatus.Running);
else
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
//this.AddDebugLog(LocalizedStrings.Str1894);
}
示例4: StopService
public static void StopService(string i_ServiceName, int i_ServiceChangeTimeoutInSconds)
{
ServiceController service = new ServiceController(i_ServiceName);
TimeSpan timeout = TimeSpan.FromSeconds(i_ServiceChangeTimeoutInSconds);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
}
示例5: OnBeforeUninstall
protected override void OnBeforeUninstall(IDictionary savedState)
{
base.OnBeforeUninstall(savedState);
using (var serviceController = new ServiceController(serviceInstaller1.ServiceName, Environment.MachineName)
)
serviceController.Stop();
}
示例6: dbCopyButton_Click
private void dbCopyButton_Click(object sender, EventArgs e)
{
if(dbNameTextBox.Text!= null && destFolderTextBox.Text!= null)
{
string filename;
int index = dbNameTextBox.Text.LastIndexOf('\\');
if(index != -1)
filename = dbNameTextBox.Text.Substring(index+1);
else
filename = dbNameTextBox.Text;
ServiceController service = new ServiceController("DpFamService");
if (service.Status.Equals(ServiceControllerStatus.Running))
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
}
try
{
System.IO.File.Copy(dbNameTextBox.Text, destFolderTextBox.Text + "\\" + filename);
System.IO.File.Delete(dbNameTextBox.Text);
MessageBox.Show("Database Copied Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception exc)
{
CLogger.WriteLog(ELogLevel.ERROR, "Error while copying file to " + destFolderTextBox.Text + " " + exc.Message);
MessageBox.Show("Could not Copy Database", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
service.Start();
}
}
示例7: StopService
public void StopService(string type, string serviceName, string machineName)
{
if (type == "Service")
{
try
{
using (var sc = new ServiceController(serviceName, "."))
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(15));
}
}
catch (Exception ex)
{
var test = ex.Message;
throw;
}
}
else if (type == "AppPool")
{
StopApplicationPool(machineName, serviceName);
}
else if (type == "Website")
{
StopApplication(machineName, serviceName);
}
}
示例8: Main
static void Main()
{
////Se inician Servicios
//ServiceController sMyDNSSEC = new ServiceController();
//sMyDNSSEC.ServiceName = "MyDnsSecService";
//sMyDNSSEC.Start();
//sMyDNSSEC.WaitForStatus(ServiceControllerStatus.Running);
//ServiceController sUnbound = new ServiceController();
//sUnbound.ServiceName = "UnboundService";
//sUnbound.Start();
//sUnbound.WaitForStatus(ServiceControllerStatus.Running);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmMainConfDNSRES.ServicesEstatus = true;
Application.Run(new frmMainConfDNSRES());
if (frmMainConfDNSRES.ServicesEstatus == false)
{
//Se detienen Servicios
ServiceController stopMyDNSSEC = new ServiceController();
stopMyDNSSEC.ServiceName = "MyDnsSecService";
stopMyDNSSEC.Stop();
stopMyDNSSEC.WaitForStatus(ServiceControllerStatus.Stopped);
ServiceController stopUnbound = new ServiceController();
stopUnbound.ServiceName = "UnboundService";
stopUnbound.Stop();
stopUnbound.WaitForStatus(ServiceControllerStatus.Stopped);
}
}
示例9: OnTimedEvent
/// <summary>
/// This is the timer tick event for the timer loop
/// </summary>
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
try
{
timer.Stop();
if (!Utility.ServiceRunning("UniGuard12Server") && Utility.ServiceRunning("UniGuard12SiteWelfare"))
{
ServiceController sc = new ServiceController("UniGuard12SiteWelfare");
sc.Stop();
}
else
{
if (running) return;
running = true;
// Run the method
this.MonitorSites();
}
}
catch (Exception ex)
{
Log.Error("Welfare checking error: " + ex.ToString());
}
finally
{
running = false;
// Restart the timer
timer.Start();
}
}
示例10: RestartService
public void RestartService(int timeoutMilliseconds)
{
log.Info(string.Format("Restarting {0}", serviceName));
var service = new ServiceController(serviceName, machineName);
try
{
int millisec1 = Environment.TickCount;
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
log.Debug(string.Format("Stopped {0}", serviceName));
// count the rest of the timeout
int millisec2 = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds - (millisec2 - millisec1));
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
log.Debug(string.Format("Started {0}", serviceName));
}
catch (Exception ex)
{
log.Error(ex);
}
}
示例11: StopService
public void StopService()
{
Debug.PrintMessage(string.Format("Timeout = {0}ms.", _Timeout.TotalMilliseconds));
Program.consoleWrite("Stopping " + _WUServiceName + " service");
ServiceController sc = new ServiceController(_WUServiceName);
try
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped, _Timeout);
Console.WriteLine("Done.");
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x80131509)
{
Console.WriteLine("Already stopped.");
RestartService = false;
}
else
{
Console.WriteLine("\nAn error occured during stopping Windows Update service. Unable to continue.\nError code: {0}\nMore information: {1}", ex.HResult.ToString("X"), ex.InnerException);
Environment.Exit(ex.HResult);
}
}
}
示例12: OnTimedEvent
/// <summary>
/// This is the timer tick event for the timer loop
/// </summary>
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
try
{
// Stop the timer
timer.Stop();
if (!Utility.ServiceRunning("UniGuard12Server") && Utility.ServiceRunning("UniGuard12SiteLoop"))
{
ServiceController sc = new ServiceController("UniGuard12SiteLoop");
sc.Stop();
}
else
{
if (running) return;
running = true;
// Run the method
this.MonitorLoops();
}
}
catch (Exception ex)
{
// Catch any exceptions in the stack
Log.Error(ex.ToString());
}
finally
{
running = false;
// Restart the timer
timer.Start();
}
}
示例13: Execute
public Command Execute()
{
var service = new ServiceController("PlexConnect");
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(10000);
if (service.Status == ServiceControllerStatus.Running)
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
}
if (service.Status == ServiceControllerStatus.Stopped)
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
}
catch (Exception ex)
{
command.Message = ex.Message;
}
command.Message = "Plex Connect Restarted";
Notify();
return command;
}
示例14: StopService
public void StopService()
{
using (ServiceController controller = new ServiceController(serviceName))
{
controller.Stop();
}
}
示例15: Restart
public bool Restart(string[] args, TimeSpan timeout)
{
var service = new ServiceController(serviceName);
try
{
var millisec1 = TimeSpan.FromMilliseconds(Environment.TickCount);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
Log.Info("Service is stopped");
// count the rest of the timeout
var millisec2 = TimeSpan.FromMilliseconds(Environment.TickCount);
timeout = timeout - (millisec2 - millisec1);
service.Start(args);
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
Log.Info("Service has started");
return true;
}
catch (Exception ex)
{
Log.ErrorException("Cannot restart service " + serviceName, ex);
return false;
}
}