namespace Service.BusinessTask; public abstract class AbstractTaskHandler { private volatile bool _stopFlag = false; public void Start() { Thread thread = new Thread(Process); thread.IsBackground = true; thread.Name = Name(); thread.Start(); } private void Process() { while (!_stopFlag) { Handle(); Thread.Sleep(Interval()); } } protected abstract int Interval(); protected abstract void Handle(); protected abstract string Name(); public void Stop() { _stopFlag = true; } }