本文整理汇总了C#中Service.Start方法的典型用法代码示例。如果您正苦于以下问题:C# Service.Start方法的具体用法?C# Service.Start怎么用?C# Service.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Service
的用法示例。
在下文中一共展示了Service.Start方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _ConnectTest
private void _ConnectTest()
{
Console.WriteLine("Connect test:");
using (Service svc = new Service("ConnectTest"))
{
svc.Start();
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7788);
// Listen
int listenSessionId = svc.Listen(endPoint);
Console.WriteLine("Listened on {0}, sessionId: {1}", endPoint, listenSessionId);
// Synchronous connect.
int connSessionId = svc.Connect(endPoint);
Console.WriteLine("Connected to {0}, sessionId: {1}", endPoint, connSessionId);
// Asynchronous connect.
svc.AsyncConn(endPoint);
// Error endpoint's asynchronous connect.
svc.AsyncConn(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7789));
Console.WriteLine("Press any key to exit connect test...");
Console.ReadKey();
}
}
示例2: StartServer
public void StartServer()
{
var hosting = new Service(9090);
hosting.Start();
for (int i = 0; i < 10; i++)
{
Thread.Sleep(200);
}
hosting.Stop();
}
示例3: Run
public void Run(string[] args)
{
Console.WriteLine("Timer test:");
using (Service svc = new Service("TimerTestSvc"))
{
svc.Start();
Console.WriteLine("Press any key to pause TimerTest...");
Console.ReadKey();
}
}
示例4: Start
private void Start()
{
Service = new Service();
BasicHttpEndpoint = new BasicHttpEndpointHandle { Address = "http://192.168.175.123:8000/FreetimeDataServices" };
Service.AddEndpointHandle(BasicHttpEndpoint);
Service.Load();
gridSessions.DataSource = Service.ServiceHosts.ToList();
SetupGrid();
Service.Start();
}
示例5: Main
private static void Main(string[] args)
{
var arguments = WindowsServiceArguments.Create(args);
Service service;
if (string.IsNullOrEmpty(arguments.ServiceWebApi))
{
service = new Service("HostR Agent", "Service agent for HostR.", arguments, null);
service.Start();
}
else
{
var credentials = new LoginCredentials { UserName = arguments.ServiceWebApiUserName, Password = arguments.ServiceWebApiPassword };
var client = string.IsNullOrWhiteSpace(credentials.UserName)
? new WindowsServiceWebClient(arguments.ServiceWebApi)
: new WindowsServiceWebClient(arguments.ServiceWebApi, credentials);
service = new Service("HostR Agent", "Service agent for HostR.", arguments, client);
service.Start();
}
}
示例6: 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();
}
}
示例7: _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();
}
示例8: _SendRecvTest
private void _SendRecvTest()
{
Console.WriteLine("Send/Recv test:");
using (Service svc = new Service("SendRecvTest"))
{
svc.Start();
IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7788);
int listenSessionId = svc.Listen(ep);
Console.WriteLine("Listened on [{0}], sessionId: {1}", ep, listenSessionId);
int connSessionId = svc.Connect(ep);
Console.WriteLine("Connected to {0}, sessionId: {1}", ep, connSessionId);
// Test Send
TestPacket data = new TestPacket();
data.intVal = 10086;
data.strVal = "Hello World";
svc.Send(connSessionId, data);
// Test Multicast
TestMulticastPacket multicastData = new TestMulticastPacket();
multicastData.intVal = 10010;
multicastData.strVal = "Multicast data";
List<int> multicastSessionIds = new List<int>();
multicastSessionIds.Add(connSessionId);
svc.Multicast(multicastSessionIds, multicastData);
// Test Broadcast
TestBroadcastPacket broadcastData = new TestBroadcastPacket();
broadcastData.intVal = 8888;
broadcastData.strVal = "Broadcast data";
svc.Broadcast(broadcastData);
// Test unhandled packet
svc.Send(connSessionId, new UnHandledPacket());
// Test coder not found
MemoryStream unhandledStream = new MemoryStream();
unhandledStream.Write(new byte[30], 0, 30);
svc.Send(connSessionId, 10086, unhandledStream);
Console.WriteLine("Press any key to exit Send/Recv test...");
Console.ReadKey();
}
}
示例9: _PreHandleTest
private void _PreHandleTest()
{
Console.WriteLine("PreHandle test:");
using (Service svc = new Service("PreHandleTest"))
{
svc.Start();
IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7788);
Console.WriteLine("Listened on {0}", ep);
int connSessionId = svc.Connect(ep);
Console.WriteLine("Connected to {0}, sessionId: {1}", ep, connSessionId);
TestPacket data = new TestPacket();
data.intVal = 10086;
data.strVal = "Hello World";
svc.Send(connSessionId, data);
Console.WriteLine("Press any key to exit PreHandle test...");
Console.ReadKey();
}
}
示例10: _ListenTest
private void _ListenTest()
{
Console.WriteLine("Listen test:");
using (Service svc = new Service("ListenTest"))
{
svc.Start();
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7788);
int sessionId = svc.Listen(endPoint);
Console.WriteLine("Listened on {0}, sessionId: {1}", endPoint, sessionId);
Console.WriteLine("Remove listen session: {0}", sessionId);
svc.RemoveSession(sessionId, "Listen test remove", true);
Console.WriteLine("Press any key to exit listen test...");
Console.ReadKey();
}
}
示例11: _FrameExcTest
private void _FrameExcTest()
{
Console.WriteLine("FrameExc test:");
using (Service svc = new Service("FrameExcTest"))
{
svc.Start();
Console.WriteLine("Press any key to exit FrameExc test...");
Console.ReadKey();
}
}
示例12: _ExternalDriveTest
private void _ExternalDriveTest()
{
Console.WriteLine("External-Drive test:");
using (var svc = new Service("ExternalDriveTest"))
{
svc.driveMode = ServiceDriveMode.ExternalDrive;
svc.Start();
svc.fps = 10;
Console.WriteLine("Service[{0}] startup, and set fps to: {1}", svc, svc.fps);
// Self drive 30 seconds
Console.WriteLine("Loop 300 times...");
for (int i = 0; i < 300; i++)
svc.OnSvc(true);
Console.WriteLine("Press any key to exit External-Drive test...");
Console.ReadKey();
}
}