本文整理汇总了C#中Service.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Service.Stop方法的具体用法?C# Service.Stop怎么用?C# Service.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Service
的用法示例。
在下文中一共展示了Service.Stop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartServer
public void StartServer()
{
var hosting = new Service(9090);
hosting.Start();
for (int i = 0; i < 10; i++)
{
Thread.Sleep(200);
}
hosting.Stop();
}
示例2: Main
private static void Main(string[] args)
{
SetupConsole();
try
{
var config = new FilterConfig("Config\\Filter.xml");
//Logger
foreach (var logger in config.Logger)
{
StaticLogger.Create(logger.Key);
StaticLogger.SetLogLevel(logger.Value.Ordinal, logger.Key);
}
StaticLogger.SetInstance();
//StaticLogger.Instance.Trace("Trace");
//StaticLogger.Instance.Debug("Debug");
//StaticLogger.Instance.Info("Info");
//StaticLogger.Instance.Warn("Warn");
//StaticLogger.Instance.Error("Error");
//StaticLogger.Instance.Fatal("Fatal");
//Services
_serviceCollection = new ServiceCollection();
foreach (var serviceSettings in config.Services)
{
var service = new Service(serviceSettings.Value);
_serviceCollection.Add(service);
}
//Plugins
var pluginManager = new PluginManager(config.Plugins);
foreach (var service in _serviceCollection)
{
pluginManager.RegisterService(service);
}
var pluginCount = pluginManager.Load();
StaticLogger.Instance.Info($"{pluginCount} plugins registered.");
//Start services
foreach (var service in _serviceCollection)
{
var result = service.Start();
if (result == false)
StaticLogger.Instance.Fatal($"Failed to start {service.Settings.Name}, check Filter.xml and prev. errors");
}
StaticLogger.Instance.Info("Successfully initilized.");
Console.Beep();
while (true)
{
var line = Console.ReadLine();
if (line == "exit" || line == "quit")
break;
}
foreach (var service in _serviceCollection)
{
service.Stop();
}
}
catch (Exception ex)
{
Console.Beep();
Console.WriteLine("Something fucked up really hard, please check Filter.xml");
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
Console.Beep();
Console.ReadLine();
}
}
示例3: _StartStopTest
private void _StartStopTest()
{
Console.WriteLine("Start/Stop service test:");
using (Service svc = new Service("StartStopTest"))
{
svc.Start();
Console.WriteLine("Start service, wait 2 seconds...");
Thread.Sleep(2000);
Console.WriteLine("Stop service...");
svc.Stop();
Console.WriteLine("ReStart service...");
svc.Start(2);
Thread.Sleep(5000);
Console.WriteLine("Stop service...");
svc.Stop();
}
Console.WriteLine("Press any key to finish Start/Stop service test...");
Console.ReadKey();
}