You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
620 B
32 lines
620 B
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;
|
|
}
|
|
} |