mirror of
https://github.com/iminet/dev.git
synced 2024-05-14 13:32:36 +02:00
Compare commits
3 Commits
920e9fa11e
...
ba3107d03c
Author | SHA1 | Date | |
---|---|---|---|
ba3107d03c | |||
c1fc82021e | |||
271e654489 |
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# This repo is for testing, developing and bug tracking only.
|
||||
Please do not fork or contribute on it.
|
60
csharp/Dotnetservice/Program.cs
Normal file
60
csharp/Dotnetservice/Program.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
// ==============================================================================================
|
||||
// For testing windows service with .NET 5
|
||||
// Source: https://stackoverflow.com/questions/7764088/net-console-application-as-windows-service
|
||||
// ==============================================================================================
|
||||
|
||||
|
||||
using System.ServiceProcess
|
||||
|
||||
public static class Program
|
||||
{
|
||||
#region Nested classes to support running as service
|
||||
public const string ServiceName = "MyService";
|
||||
|
||||
public class Service : ServiceBase
|
||||
{
|
||||
public Service()
|
||||
{
|
||||
ServiceName = Program.ServiceName;
|
||||
}
|
||||
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
Program.Start(args);
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
Program.Stop();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (!Environment.UserInteractive)
|
||||
// running as service
|
||||
using (var service = new Service())
|
||||
ServiceBase.Run(service);
|
||||
else
|
||||
{
|
||||
// running as console app
|
||||
Start(args);
|
||||
|
||||
Console.WriteLine("Press any key to stop...");
|
||||
Console.ReadKey(true);
|
||||
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private static void Start(string[] args)
|
||||
{
|
||||
// onstart code here
|
||||
}
|
||||
|
||||
private static void Stop()
|
||||
{
|
||||
// onstop code here
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user