本文整理汇总了C#中ServiceControllerStatus类的典型用法代码示例。如果您正苦于以下问题:C# ServiceControllerStatus类的具体用法?C# ServiceControllerStatus怎么用?C# ServiceControllerStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceControllerStatus类属于命名空间,在下文中一共展示了ServiceControllerStatus类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetServiceList
/// <summary>
/// 获取服务列表
/// </summary>
/// <returns></returns>
public static IList<ServiceInformation> GetServiceList(string contains, ServiceControllerStatus status)
{
IList<ServiceInformation> servicelist = new List<ServiceInformation>();
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController s in services)
{
if (s.Status != status) continue;
if (string.IsNullOrEmpty(contains))
{
servicelist.Add(new ServiceInformation(s.ServiceName));
}
else
{
if (s.ServiceName != null && s.ServiceName.ToLower().Contains(contains.ToLower()))
{
servicelist.Add(new ServiceInformation(s.ServiceName));
}
else if (s.DisplayName != null && s.DisplayName.ToLower().Contains(contains.ToLower()))
{
servicelist.Add(new ServiceInformation(s.ServiceName));
}
}
}
return servicelist;
}
开发者ID:rajayaseelan,项目名称:mysoftsolution,代码行数:30,代码来源:InstallerUtils.cs
示例2: ChangeServiceStatus
/// <summary>
/// Checks the status of the given controller, and if it isn't the requested state,
/// performs the given action, and checks the state again.
/// </summary>
/// <param name="controller"></param>
/// <param name="status"></param>
/// <param name="changeStatus"></param>
public static void ChangeServiceStatus(ServiceController controller, ServiceControllerStatus status, Action changeStatus)
{
if (controller.Status == status)
{
Console.Out.WriteLine(controller.ServiceName + " status is good: " + Enum.GetName(typeof(ServiceControllerStatus), status));
return;
}
Console.Out.WriteLine((controller.ServiceName + " status is NOT " + Enum.GetName(typeof(ServiceControllerStatus), status) + ". Changing status..."));
try
{
changeStatus();
}
catch (Win32Exception exception)
{
ThrowUnableToChangeStatus(controller.ServiceName, status, exception);
}
catch (InvalidOperationException exception)
{
ThrowUnableToChangeStatus(controller.ServiceName, status, exception);
}
var timeout = TimeSpan.FromSeconds(3);
controller.WaitForStatus(status, timeout);
if (controller.Status == status)
Console.Out.WriteLine((controller.ServiceName + " status changed successfully."));
else
ThrowUnableToChangeStatus(controller.ServiceName, status);
}
开发者ID:petarvucetin,项目名称:NServiceBus,代码行数:37,代码来源:ProcessUtil.cs
示例3: ControlService
bool ControlService(ServiceControllerStatus status, Action<ServiceController> controlAction)
{
if (controller.Status == status)
{
log.Debug("The {0} service is already in the requested state: {1}", controller.ServiceName, status);
return false;
}
log.Debug("Setting the {0} service to {1}", controller.ServiceName, status);
try
{
controlAction(controller);
}
catch (Exception ex)
{
string message = string.Format("The {0} service could not be set to {1}", controller.ServiceName, status);
throw new InvalidOperationException(message, ex);
}
controller.WaitForStatus(status, timeout);
if (controller.Status == status)
{
log.Debug("The {0} service was set to {1} successfully", controller.ServiceName, status);
}
else
{
string message = string.Format("A timeout occurred waiting for the {0} service to be {1}",
controller.ServiceName,
status);
throw new InvalidOperationException(message);
}
return true;
}
开发者ID:alexmg,项目名称:Rebus,代码行数:35,代码来源:WindowsService.cs
示例4: InitializeTrayIconAndProperties
public void InitializeTrayIconAndProperties()
{
serviceStatus = _serviceManager.GetServiceStatus();
//Set the Tray icon
if (serviceStatus == ServiceControllerStatus.Running)
notifyTrayIcon.Icon = Properties.Resources.TrayIconRunning;
else if (serviceStatus == ServiceControllerStatus.Stopped)
notifyTrayIcon.Icon = Properties.Resources.TrayIconStopped;
else
notifyTrayIcon.Icon = Properties.Resources.TrayIconActive;
//Setup context menu options
trayContextMenu = new ContextMenuStrip();
trayContextMenu.Items.Add(new ToolStripMenuItem() { Name = ActionConstants.REFRESH, Text = "Refresh Status" });
trayContextMenu.Items.Add("-");
_startServiceItem = new ToolStripMenuItem() { Enabled = ServiceControllerStatus.Stopped.Equals(serviceStatus), Name = ActionConstants.START_SERVICE, Text = "Start Service" };
trayContextMenu.Items.Add(_startServiceItem);
_stopServiceItem = new ToolStripMenuItem() { Enabled = ServiceControllerStatus.Running.Equals(serviceStatus), Name = ActionConstants.STOP_SERVICE, Text = "Stop Service" };
trayContextMenu.Items.Add(_stopServiceItem);
trayContextMenu.Items.Add("-");
trayContextMenu.Items.Add(new ToolStripMenuItem() { Name = ActionConstants.SHOW_LOGS, Text = "Show Logs" });
trayContextMenu.Items.Add("-");
trayContextMenu.Items.Add(new ToolStripMenuItem() { Name = "actionExit", Text = "Exit" });
trayContextMenu.ItemClicked += trayContextMenu_ItemClicked;
//Initialize the tray icon here
this.notifyTrayIcon.ContextMenuStrip = trayContextMenu;
}
开发者ID:electricneuron,项目名称:jonel.communicationservice,代码行数:34,代码来源:FormApp.cs
示例5: RestoreService
private void RestoreService(ServiceControllerStatus previousStatus)
{
if (previousStatus == ServiceControllerStatus.Running) {
controller.Start();
} else if (previousStatus == ServiceControllerStatus.Paused) {
controller.Pause();
}
}
开发者ID:siwater,项目名称:ssd_library,代码行数:8,代码来源:AgentController.cs
示例6: serviceTimer_Tick
private void serviceTimer_Tick (object sender, EventArgs e) {
try {
lastError = null;
lastStatus = serviceController.Status;
} catch (Exception ex) {
lastStatus = ServiceControllerStatus.Paused;
lastError = ex;
}
UpdateStatus ();
}
开发者ID:pearjoint,项目名称:smoothio,代码行数:10,代码来源:MainForm.cs
示例7: ThrowUnableToChangeStatus
private static void ThrowUnableToChangeStatus(string serviceName, ServiceControllerStatus status, Exception exception)
{
var message = "Unable to change " + serviceName + " status to " + Enum.GetName(typeof(ServiceControllerStatus), status);
if (exception == null)
{
throw new InvalidOperationException(message);
}
throw new InvalidOperationException(message, exception);
}
开发者ID:petarvucetin,项目名称:NServiceBus,代码行数:11,代码来源:ProcessUtil.cs
示例8: ToServiceStatus
static ServiceStatus ToServiceStatus(ServiceControllerStatus status)
{
switch (status)
{
case ServiceControllerStatus.StopPending:
return ServiceStatus.Stopped;
case ServiceControllerStatus.Stopped:
return ServiceStatus.Stopped;
default:
return ServiceStatus.Started;
}
}
开发者ID:pragmatrix,项目名称:Dominator,代码行数:12,代码来源:ServiceTools.cs
示例9: CheckStatus
private bool CheckStatus(ServiceControllerStatus status)
{
try
{
this.service.Refresh();
return this.service.Status == status;
}
catch (InvalidOperationException)
{
return false;
}
}
开发者ID:d1ce,项目名称:PhpVersionSwitcher,代码行数:12,代码来源:ServiceManager.cs
示例10: ServiceController
internal ServiceController(string machineName, System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS_PROCESS status)
{
this.machineName = ".";
this.name = "";
this.displayName = "";
this.eitherName = "";
if (!SyntaxCheck.CheckMachineName(machineName))
{
throw new ArgumentException(Res.GetString("BadMachineName", new object[] { machineName }));
}
this.machineName = machineName;
this.name = status.serviceName;
this.displayName = status.displayName;
this.commandsAccepted = status.controlsAccepted;
this.status = (ServiceControllerStatus) status.currentState;
this.type = status.serviceType;
this.statusGenerated = true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:18,代码来源:ServiceController.cs
示例11: TranslateServiceStatus
/// <summary>
/// Maps the status of eam service to value specified in resources.
/// </summary>
/// <param name="status"></param>
/// <returns></returns>
public static String TranslateServiceStatus(ServiceControllerStatus status)
{
if (status == ServiceControllerStatus.Running)
return Resources.Strings.EAMservice_Running;
if (status == ServiceControllerStatus.Stopped)
return Resources.Strings.EAMservice_Stop;
if (status == ServiceControllerStatus.ContinuePending)
return Resources.Strings.EAMservice_ContinuePending;
if (status == ServiceControllerStatus.Paused)
return Resources.Strings.EAMservice_Paused;
if (status == ServiceControllerStatus.PausePending)
return Resources.Strings.EAMservice_PausePending;
if (status == ServiceControllerStatus.StartPending)
return Resources.Strings.EAMservice_StartPending;
if (status == ServiceControllerStatus.StopPending)
return Resources.Strings.EAMservice_StopPending;
return "";
}
开发者ID:vinhdoan,项目名称:Angroup.demo,代码行数:23,代码来源:ServiceView.cs
示例12: ChangeServiceStatus
/// <summary>
/// Checks the status of the given controller, and if it isn't the requested state,
/// performs the given action, and checks the state again.
/// </summary>
/// <param name="controller"></param>
/// <param name="status"></param>
/// <param name="changeStatus"></param>
public static void ChangeServiceStatus(ServiceController controller, ServiceControllerStatus status, Action changeStatus)
{
if (controller.Status == status)
{
Logger.Debug(controller.ServiceName + " status is good: " + Enum.GetName(typeof(ServiceControllerStatus), status));
return;
}
Logger.Debug(controller.ServiceName + " status is NOT " + Enum.GetName(typeof(ServiceControllerStatus), status) + ". Changing status...");
changeStatus();
var timeout = TimeSpan.FromSeconds(3);
controller.WaitForStatus(status, timeout);
if (controller.Status == status)
Logger.Debug(controller.ServiceName + " status changed successfully.");
else
throw new InvalidOperationException("Unable to change " + controller.ServiceName + " status to " + Enum.GetName(typeof(ServiceControllerStatus), status));
}
开发者ID:togakangaroo,项目名称:NServiceBus,代码行数:26,代码来源:ProcessUtil.cs
示例13: TrySetStatus
private Task<bool> TrySetStatus(ServiceControllerStatus status, Action method)
{
return Task.Run(() =>
{
var timeSpan = TimeSpan.FromSeconds(WaitTime);
try
{
method();
this.service.WaitForStatus(status, timeSpan);
}
catch (System.ServiceProcess.TimeoutException) { }
catch (InvalidOperationException)
{
Task.Delay(timeSpan).Wait(); // force-wait
}
return this.CheckStatus(status);
});
}
开发者ID:d1ce,项目名称:PhpVersionSwitcher,代码行数:20,代码来源:ServiceManager.cs
示例14: RunServer
/// <summary>
/// Change the service status
/// </summary>
/// <param name="sc"></param>
/// <param name="newStatus"></param>
public static void RunServer(ServiceController sc, ServiceControllerStatus newStatus)
{
try
{
if (sc.Status == newStatus)
return;
// TODO: Need better waiting mechanism (ideally show a progress bar here...)
// for now wait 30 seconds and confirm the new status afterward.
var waitAmount = new TimeSpan(0, 0, 30);
switch (newStatus)
{
case ServiceControllerStatus.Running:
//Status("Starting server, please wait...");
sc.Start();
sc.WaitForStatus(newStatus, waitAmount);
break;
case ServiceControllerStatus.Stopped:
//Status("Stopping server, please wait...");
sc.Stop();
sc.WaitForStatus(newStatus, waitAmount);
break;
default:
throw new Exception("Unsupported action = " + newStatus.ToString());
}
if (sc.Status != newStatus)
throw new ApplicationException("Service is not " + newStatus);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw;
}
}
开发者ID:dbremner,项目名称:hycs,代码行数:44,代码来源:serviceUtil.cs
示例15: MonitorService
internal void MonitorService()
{
serviceStatus = ServiceControllerStatus.Stopped;
System.Threading.Thread.Sleep(3000);
bool first = true;
while (RunMonitor)
{
try
{
ServiceControllerStatus status = PVServiceManager.GetServiceStatus();
if (status != serviceStatus || first || ForceRefresh)
{
SynchronizationContext.Post(new SendOrPostCallback(delegate
{
ServiceStatusChangeNotification(status);
}), null);
//ServiceStatusChangeNotification(svc.Status);
first = ForceRefresh; // avoid race - do it twice
ForceRefresh = false;
}
serviceStatus = status;
}
catch (Exception)
{
SynchronizationContext.Post(new SendOrPostCallback(delegate
{
ServiceStatusChangeNotification(ServiceControllerStatus.Stopped);
}), null);
}
System.Threading.Thread.Sleep(3000);
}
}
开发者ID:alberthoekstra,项目名称:PVBeanCounter,代码行数:36,代码来源:ManageService.cs
示例16: StopStartServices
public static bool StopStartServices(string serviceName, ServiceControllerStatus status)
{
bool result = false;
try
{
ServiceController sc = new ServiceController(serviceName);
if (status == ServiceControllerStatus.StopPending)
{
if (sc.Status != ServiceControllerStatus.Stopped)
sc.Stop();
}
else if (status == ServiceControllerStatus.StartPending)
{
if (sc.Status != ServiceControllerStatus.Running)
sc.Start();
}
result = true;
}
catch (Exception)
{
}
return result;
}
开发者ID:petredimov,项目名称:Intrensic,代码行数:24,代码来源:ServiceUtility.cs
示例17: UpdateServiceUI
private void UpdateServiceUI()
{
if (mediaServer != null && standAloneMode == true)
{
serverStatus1.Text = "Serving " + mediaServer.TotalFileCount + " Files in " + mediaServer.TotalDirectoryCount + " Directories";
serverStatus2.Text = "";
UpdateDirectoriesUI();
return;
}
if (serviceController == null)
{
try
{
serviceController = new ServiceController("AV Media Server");
serviceStatus = serviceController.Status;
}
catch (System.InvalidOperationException)
{
serverStatus1.Text = "Media Server Service Not Installed";
serverStatus2.Text = "Use \"Standalone Mode\" for autonomous operation";
serviceController = null;
serviceStatus = ServiceControllerStatus.Stopped;
return;
}
}
ServiceController serviceController2 = new ServiceController("AV Media Server");
serviceStatus = serviceController2.Status;
switch (serviceStatus)
{
case ServiceControllerStatus.Running:
if (mediaServer == null)
{
serverStatus1.Text = "Connecting...";
serverStatus2.Text = "";
Connect();
}
else
{
serverStatus1.Text = "Media Server Serving "+mediaServer.TotalFileCount+" Files in "+mediaServer.TotalDirectoryCount+" Directories";
serverStatus2.Text = "";
}
break;
case ServiceControllerStatus.Stopped:
serverStatus1.Text = "Media Server Service is Stopped";
serverStatus2.Text = "";
break;
default:
serverStatus1.Text = "Media Server Service is " + serviceStatus.ToString();
serverStatus2.Text = "";
break;
}
serviceController2.Close();
serviceController2.Dispose();
serviceController2 = null;
UpdateDirectoriesUI();
}
开发者ID:amadare,项目名称:DeveloperToolsForUPnP,代码行数:58,代码来源:MainForm.cs
示例18: MainForm
public MainForm(string[] args)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
OpenSource.UPnP.DText p = new OpenSource.UPnP.DText();
p.ATTRMARK = "=";
string[] filePaths = new string[1];
foreach(string arg in args)
{
p[0] = arg;
switch(p[1].ToUpper())
{
case "-UDN":
MediaServerCore.CustomUDN = p[2];
break;
case "-CACHETIME":
MediaServerCore.CacheTime = int.Parse(p[2]);
break;
case "-INMPR":
MediaServerCore.INMPR = !(p[2].ToUpper()=="NO");
break;
}
}
// Setup the UI
transfersSplitter.Visible = viewTransfersPanelMenuItem.Checked;
transfersListView.Visible = viewTransfersPanelMenuItem.Checked;
try
{
serviceController = new ServiceController("UPnP Media Server");
serviceStatus = serviceController.Status;
OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,"Service control mode...");
}
catch (System.InvalidOperationException)
{
serviceController = null;
serviceStatus = ServiceControllerStatus.Stopped;
OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,"Stand alone mode...");
}
if (serviceController != null)
{
// Service controller mode
serviceMenuItem.Visible = true;
// Pause State
pauseServerMenuItem.Visible = false;
System.Collections.Specialized.ListDictionary channelProperties = new System.Collections.Specialized.ListDictionary();
channelProperties.Add("port", 12330);
HttpChannel channel = new HttpChannel(channelProperties,
new SoapClientFormatterSinkProvider(),
new SoapServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel, false);
OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,"RegisterChannel");
if (serviceStatus == ServiceControllerStatus.Running)
{
OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,"RegisterWellKnownClientType");
RemotingConfiguration.RegisterWellKnownClientType(
typeof(UPnPMediaServer),
"http://localhost:12329/UPnPMediaServer/UPnPMediaServer.soap"
);
registeredServerType = true;
}
}
else
{
// Stand alone mode
if (registeredServerType == true || standAloneMode == true) return;
standAloneMode = true;
serviceMenuItem.Visible = false;
// Stand alone mode
mediaServerCore = new MediaServerCore("Media Server (" + System.Windows.Forms.SystemInformation.ComputerName + ")");
this.mediaServerCore.OnDirectoriesChanged += new MediaServerCore.MediaServerCoreEventHandler(this.Sink_OnDirectoriesChanged);
mediaServer = new UPnPMediaServer();
// Pause State
pauseServerMenuItem.Checked = this.mediaServerCore.IsPaused;
}
UpdateServiceUI();
foreach(string arg in args)
{
p[0] = arg;
switch(p[1].ToUpper())
{
case "-P":
filePaths[0] = p[2];
try
{
this.AddDirs(filePaths);
}
//.........这里部分代码省略.........
开发者ID:amadare,项目名称:DeveloperToolsForUPnP,代码行数:101,代码来源:MainForm.cs
示例19: HandleServiceState
private void HandleServiceState(ServiceControllerStatus _status)
{
switch (_status)
{
case ServiceControllerStatus.Stopped:
triggerButton.Content = UI.Start;
stateLabel.Content = UI.ServiceStopped;
stateLabel.Foreground = Brushes.Red;
break;
case ServiceControllerStatus.Running:
triggerButton.Content = UI.Stop;
stateLabel.Content = UI.ServiceStarted;
stateLabel.Foreground = Brushes.Green;
break;
case ServiceControllerStatus.StartPending:
triggerButton.Content = UI.Stop;
stateLabel.Content = UI.ServiceStartingFixed;
stateLabel.Foreground = Brushes.Teal;
break;
default:
triggerButton.Foreground = Brushes.Teal;
stateLabel.Content = UI.ServiceUnknown;
stateLabel.Foreground = Brushes.Teal;
break;
}
}
开发者ID:puenktchen,项目名称:MPExtended,代码行数:26,代码来源:ServiceControlInterface.cs
示例20: CreateMockedController
private ServiceControllerProxy CreateMockedController(
ServiceControllerStatus? status = ServiceControllerStatus.Running)
{
var mockController = new Mock<ServiceControllerProxy>();
if (status != null)
{
mockController.Setup(m => m.Status).Returns(status.Value);
}
else
{
mockController.Setup(m => m.Status).Throws(new InvalidOperationException());
}
return mockController.Object;
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:16,代码来源:ConnectionFactoryConfigTests.cs
注:本文中的ServiceControllerStatus类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论