250
|
1 using System;
|
|
2 using System.Threading;
|
|
3 using System.Threading.Tasks;
|
|
4
|
|
5 namespace Implab.Components
|
|
6 {
|
|
7 public class RunnableComponent : IRunnable {
|
|
8
|
|
9 readonly object m_lock = new object();
|
|
10
|
|
11 CancellationTokenSource m_cts;
|
|
12
|
|
13 public Task<ExecutionState> Completion {
|
|
14 get;
|
|
15 private set;
|
|
16 }
|
|
17
|
|
18 public ExecutionState State => throw new NotImplementedException();
|
|
19
|
|
20 public Exception LastError => throw new NotImplementedException();
|
|
21
|
|
22 public event EventHandler<StateChangeEventArgs> StateChanged;
|
|
23
|
|
24 public void Dispose() {
|
|
25 lock(m_lock) {
|
|
26 Dispose(true);
|
|
27 GC.SuppressFinalize(this);
|
|
28 }
|
|
29 }
|
|
30
|
|
31 protected virtual void Dispose(bool disposing) {
|
|
32 if (disposing) {
|
|
33 Safe.Dispose(m_cts);
|
|
34 }
|
|
35 }
|
|
36
|
|
37 public void Start(CancellationToken ct) {
|
|
38 lock(m_lock) {
|
|
39 switch (State)
|
|
40 {
|
|
41
|
|
42 default:
|
|
43 throw new InvalidOperationException();
|
|
44 }
|
|
45 }
|
|
46 }
|
|
47
|
|
48 public void Stop(CancellationToken ct) {
|
|
49 throw new NotImplementedException();
|
|
50 }
|
|
51
|
|
52 protected virtual Task StartImpl(CancellationToken ct) {
|
|
53
|
|
54 return Task.CompletedTask;
|
|
55 }
|
|
56 }
|
|
57 } |