kmSqlReplicate/ClassObj/ServiceMain.cs

36 lines
756 B
C#
Raw Permalink Normal View History

2025-09-02 04:03:07 -04:00
using log4net;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
namespace kmSqlReplicate.ClassObj;
internal class ServiceMain : ServiceControl
{
private ConcurrentBag<Task> _tasks = new();
internal ILog appLog = LogManager.GetLogger(Program.AppName);
public bool Start(HostControl hostControl)
{
_tasks.Add(Task.Run(() =>
{
var z = new ClassObj.ClsReplicateBase();
z.Go();
}));
return true;
}
public bool Stop(HostControl hostControl)
{
Program.exitNow = true;
Task.WaitAll(_tasks.ToArray());
Console.WriteLine("I've Successfully Killed All Tasks!");
return true;
}
}