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