本文整理汇总了C#中System.ServiceProcess.ServiceBase.StopService方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceBase.StopService方法的具体用法?C# ServiceBase.StopService怎么用?C# ServiceBase.StopService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceProcess.ServiceBase
的用法示例。
在下文中一共展示了ServiceBase.StopService方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
internal static void Main(string[] args)
{
IArguments argsDictionary = new CommandArgs(args);
var backgroundService = new KonfDBH(argsDictionary);
var services = new ServiceBase[] {backgroundService};
if (argsDictionary.ContainsKey("install"))
{
ManagedInstallerClass.InstallHelper(new[]
{
Assembly.GetExecutingAssembly().Location
});
}
else if (argsDictionary.ContainsKey("uninstall"))
{
ManagedInstallerClass.InstallHelper(new[]
{
"/u",
Assembly.GetExecutingAssembly().Location
});
}
else if (argsDictionary.ContainsKey("console")) // console mode
{
#region Console
var contextSettings = new ContextSettings
{
CommandFactory = new CommandFactory()
};
HostContext.CreateFrom(argsDictionary.GetValue("configPath", "konfdb.json"), contextSettings);
CurrentHostContext.Default.Log.Debug("Running in Console Mode");
Console.SetWindowPosition(0, 0);
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.ForegroundColor = ConsoleColor.White;
Console.Clear();
services.RunService();
var shutdown = new ManualResetEvent(false);
var thread = new Thread(() =>
{
while (!shutdown.WaitOne(0))
{
Thread.Sleep(1000);
}
});
thread.Start();
bool exitLoop = false;
var commandService = backgroundService.ServiceFacade;
string internalSessionId = Guid.NewGuid().ToString();
while (!exitLoop)
{
Console.Write(">");
string line = Console.ReadLine();
if (string.IsNullOrEmpty(line)) continue;
var commandOutput = commandService.ExecuteCommand(new ServiceRequestContext
{
Command = line,
Token = backgroundService.AuthenticationToken,
SessionId = internalSessionId
});
if (commandOutput == null) continue;
if (commandOutput.MessageType == CommandOutput.DisplayMessageType.Message)
Console.WriteLine(commandOutput.Data != null
? commandOutput.Data.ToJson()
: commandOutput.DisplayMessage);
else if (commandOutput.MessageType == CommandOutput.DisplayMessageType.Error)
Console.WriteLine(commandOutput.DisplayMessage);
if (commandOutput.PostAction == CommandOutput.PostCommandAction.ExitApplication)
{
shutdown.Set();
thread.Join();
services.StopService();
CurrentHostContext.Default.Log.Info("Exiting...");
Thread.Sleep(500);
exitLoop = true;
}
}
#endregion
}
else
{
ServiceBase.Run(services);
}
}