Ejemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                ScanCancellationTokenSource?.Dispose();

                if (Workers != null)
                {
                    foreach (var worker in Workers)
                    {
                        worker.Task.Dispose();
                        worker.CancellationTokenSource?.Dispose();
                    }
                }
            }

            ScannerQueues = null;
            Workers       = null;

            _disposed = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Stops the scanning process
        /// </summary>
        /// <returns></returns>
        public async Task StopAsync()
        {
            await Task.Run(() =>
            {
                OnCanceling?.Invoke(this, new EventArgs {
                });

                ScanCancellationTokenSource.Cancel();

                Task.WhenAll(Workers.Select(w => w.Task)).ContinueWith((t) =>
                {
                    OnCanceled?.Invoke(this, new EventArgs {
                    });
                }).Wait();
            });
        }