Mercurial > pub > ImplabNet
comparison Implab/Components/RunnableComponent.cs @ 250:9f63dade3a40 v3
Working on runnable component
author | cin |
---|---|
date | Thu, 01 Feb 2018 02:43:35 +0300 |
parents | |
children | 7c7e9ad6fe4a |
comparison
equal
deleted
inserted
replaced
249:d82909310094 | 250:9f63dade3a40 |
---|---|
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 } |