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;
  }
}
