diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab/Components/RunnableComponent.cs	Thu Feb 01 02:43:35 2018 +0300
@@ -0,0 +1,57 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Implab.Components
+{
+    public class RunnableComponent : IRunnable {
+
+        readonly object m_lock = new object();
+
+        CancellationTokenSource m_cts;
+
+        public Task<ExecutionState> Completion {
+            get;
+            private set;
+        }
+
+        public ExecutionState State => throw new NotImplementedException();
+
+        public Exception LastError => throw new NotImplementedException();
+
+        public event EventHandler<StateChangeEventArgs> StateChanged;
+
+        public void Dispose() {
+            lock(m_lock) {
+                Dispose(true);
+                GC.SuppressFinalize(this);
+            }
+        }
+
+        protected virtual void Dispose(bool disposing) {
+            if (disposing) {
+                Safe.Dispose(m_cts);
+            }
+        }
+
+        public void Start(CancellationToken ct) {
+            lock(m_lock) {
+                switch (State)
+                {
+                    
+                    default:
+                        throw new InvalidOperationException();
+                }
+            }
+        }
+
+        public void Stop(CancellationToken ct) {
+            throw new NotImplementedException();
+        }
+
+        protected virtual Task StartImpl(CancellationToken ct) {
+
+            return Task.CompletedTask;
+        }
+    }
+}
\ No newline at end of file