-
Notifications
You must be signed in to change notification settings - Fork 0
/
Processor.cs
42 lines (37 loc) · 1011 Bytes
/
Processor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConcurrentEx
{
public abstract class Processor
{
private readonly int _processId;
private static int _lastProcessId = 1;
protected bool _isRunning; // Use State machine : 0 - ready , 1 - running , 2- Finished , 3 - canceled , 4- Error
public Processor()
{
_processId = _lastProcessId++;
_isRunning = false;
}
public Task Start()
{
if (!_isRunning)
{
_isRunning = true;
return Task.Run(() => StartProcessing());
}
return Task.CompletedTask;
}
public void Stop()
{
if (_isRunning)
{
Console.WriteLine("Stopping.....");
_isRunning = false;
}
}
protected abstract Task StartProcessing();
}
}