/// <summary> /// Startup Queues /// </summary> /// <param name="serial"></param> public static void Start(SerialPort serial) { Stop(); if (_cts == null) { _cts = new CancellationTokenSource(); } var ct = _cts.Token; _skyWatcher = new SkyWatcher(serial); _resultsDictionary = new ConcurrentDictionary <long, ISkyCommand>(); _commandBlockingCollection = new BlockingCollection <ISkyCommand>(); Task.Factory.StartNew(() => { while (!ct.IsCancellationRequested) { foreach (var command in _commandBlockingCollection.GetConsumingEnumerable()) { ProcessCommandQueue(command); } } }, ct); IsRunning = true; }
/// <summary> /// Stop /// </summary> public static void Stop() { IsRunning = false; _cts?.Cancel(); _cts?.Dispose(); _cts = null; _skyWatcher = null; _resultsDictionary = null; _commandBlockingCollection = null; }