コード例 #1
0
        /// <summary>
        /// Stops the running application
        /// </summary>
        /// <returns></returns>
        public async Task StopAsync()
        {
            Cancellation.Cancel();
            await Startup.ShutdownAsync();

            Running = false;
        }
コード例 #2
0
 public Task CancelTask()
 {
     return(Task.Run(() =>
     {
         Cancellation.Cancel();
     }));
 }
コード例 #3
0
        static void Main()
        {
            // BeforeTpl.QueueUserWorkItem();
            // BeforeTpl.QueueUserWorkItemWaitingToFinish();

            CreationAndWaiting.CreateAndWait();
            CreationAndWaiting.TaskRun();
            CreationAndWaiting.ParametrizedTask();
            CreationAndWaiting.TaskFromResult();
            CreationAndWaiting.WaitAllWaitAny();
            CreationAndWaiting.WhenAllWhenAny();
            CreationAndWaiting.Statuses();

            Continuation.Parent();
            Continuation.ContinueWith();
            Continuation.MultipleContinuations();
            Continuation.TaskStatusWhenContinueWith();
            Continuation.ContinueWhenAllWhenAny();

            Exceptions.WaitAndStatus();
            Exceptions.ContinueWith();
            Exceptions.HandleAndFlatten();

            Cancellation.Cancel();
        }
コード例 #4
0
 public void Cancel()
 {
     if (!_isDisposed)
     {
         Cancellation.Cancel();
     }
 }
コード例 #5
0
 private void excludeAllButton_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem item in addressListView.Items)
     {
         Exclusions.Add((IntPtr)ulong.Parse(item.SubItems[0].Text, System.Globalization.NumberStyles.HexNumber));
     }
     addressListView.Items.Clear();
     Cancellation?.Cancel();
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: ty4git/multithreaded-gzip
        public static void Main(string[] args)
        {
            Console.WriteLine("Use pattern: (compress | decompress) <source file name> <output file name>");

            var currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += (sender, eventArgs) =>
            {
                Console.WriteLine((Exception)eventArgs.ExceptionObject);
                Environment.Exit(1);
            };

            ValidateArgs(args);

            var cancellation = new Cancellation();

            Console.WriteLine("Press Ctrl-C to cancel.");
            var cancelledEvent = new AutoResetEvent(false);

            Console.CancelKeyPress += (sender, args) =>
            {
                cancellation.Cancel();
                args.Cancel = true;
                cancelledEvent.Set();
            };

            var isCompression  = args[0] == "compress";
            var sourceFileName = args[1];
            var targetFileName = args[2];

            var finishedEvent     = new AutoResetEvent(false);
            var sourceFile        = new FileWrapper(sourceFileName);
            var targetFile        = new FileWrapper(targetFileName);
            var blockingQueueSize = Environment.ProcessorCount * 2;
            var partSize          = 1024 * 16;

            var parallelArchiver = isCompression
                ? (IParallelArchiver) new ParallelCompressor(sourceFile, targetFile, blockingQueueSize, partSize)
                : new ParallelDecompressor(sourceFile, targetFile, blockingQueueSize, partSize);

            parallelArchiver.Process(() => { finishedEvent.Set(); }, cancellation);

            var eventWaitHandles = new[] { finishedEvent, cancelledEvent };
            var eventIndex       = WaitHandle.WaitAny(eventWaitHandles);

            if (eventWaitHandles[eventIndex] == finishedEvent)
            {
                Console.WriteLine("Application has finished successfully.");
            }
            else
            {
                Console.WriteLine("Application has been cancelled.");
            }

            Environment.ExitCode = 0;
        }
コード例 #7
0
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Cancellation cancellation = _fileTransferCancellation;

            if (cancellation != null)
            {
                cancellation.Cancel();
                buttonCancel.Enabled = false;
            }
        }
コード例 #8
0
ファイル: Task.cs プロジェクト: kknet/LiplisMoonLight
        public void Cancel(Exception e)
        {
            if (Cancellation == null)
            {
                throw new InvalidOperationException("Can't cancel Task.");
            }

            Cancellation.Cancel(e);

            MoveNext();
        }
        protected override void AdditionalSetUp()
        {
            ConsumerErrorStrategy.HandleConsumerCancelled(null)
            .ReturnsForAnyArgs(AckStrategies.Ack);

            StartConsumer((body, properties, info) =>
            {
                Cancellation.Cancel();
                Cancellation.Token.ThrowIfCancellationRequested();
            });
            DeliverMessage();
        }
コード例 #10
0
ファイル: TaskManager.cs プロジェクト: stephenpatten/cavity
        public virtual void Stop()
        {
            Trace.WriteLineIf(Tracing.Is.TraceVerbose, string.Empty);
            if (null == Timer)
            {
                return;
            }

            Timer.Dispose();
            Timer = null;
            Cancellation.Cancel();
        }
コード例 #11
0
        /// <summary>
        /// Break Updating Operation using cancellation object
        /// This method is supported by version 18.7 or greater
        /// </summary>
        public static void BreakUpdatingUsingCancellationObject()
        {
            // Creating cancellation object
            Cancellation cancellation = new Cancellation();

            // Load index
            Index index = new Index(Utilities.indexPath);

            // Updating
            index.UpdateAsync(cancellation);


            // Cancelling
            cancellation.Cancel();
        }
コード例 #12
0
        /// <summary>
        /// Break indexing with cancellation object
        /// This method is supported by version 18.7 or greater
        /// </summary>
        public static void BreakIndexingWithCancellationObject()
        {
            // Creating cancellation object
            Cancellation cancellation = new Cancellation();

            // Creating index
            Index index = new Index(Utilities.indexPath);

            // Indexing
            index.AddToIndexAsync(Utilities.documentsPath, cancellation);

            // Cancelling after 1 second of indexing
            Thread.Sleep(1000);
            cancellation.Cancel();
        }
コード例 #13
0
        /// <summary>
        /// Break Index Repository using Cancellation Object
        /// This method is supported by version 18.8 or greater
        /// </summary>
        public static void BreakIndexRepositoryUsingCancellationObject()
        {
            string          documentsFolder = Utilities.documentsPath;
            IndexRepository repository      = new IndexRepository();
            Index           index           = repository.Create();

            index.AddToIndex(documentsFolder);

            Cancellation cnc = new Cancellation();

            // Updating all indexes in repository
            repository.UpdateAsync(cnc);

            // Canceling all operations in index repository
            cnc.Cancel();
        }
コード例 #14
0
ファイル: JobTracker.cs プロジェクト: terryzamal/DotStd
 public void SetFailureMsg(string failureMsg)
 {
     // Cancel the job/worker because it failed.
     if (IsCancelled)
     {
         return;
     }
     if (string.IsNullOrWhiteSpace(failureMsg))
     {
         failureMsg = null;
     }
     this.FailureMsg = failureMsg;
     if (failureMsg != null)
     {
         Cancellation?.Cancel();
     }
 }
コード例 #15
0
        public void Start()
        {
            if (Status == ListenerStatus.Listening)
            {
                return;
            }

            Cancellation?.Cancel();
            Cancellation = new CancellationTokenSource();
            Cancellation.Token.Register(() => RaiseStatusChanged(ListenerStatus.NotListening));

            try {
                Start(Cancellation.Token);
                RaiseStatusChanged(ListenerStatus.Listening);
            } catch {
                RaiseStatusChanged(ListenerStatus.PortNotFree);
            }
        }
コード例 #16
0
        /// <summary>
        /// Starts listening for incoming connections
        /// </summary>
        public override void Start()
        {
            Cancellation?.Cancel();
            Cancellation = new CancellationTokenSource();
            var token    = Cancellation.Token;
            var listener = new HttpListener();

            token.Register(() => listener.Close());

            listener.Prefixes.Add(Prefix);
            if (Prefix.EndsWith("/announce/", StringComparison.OrdinalIgnoreCase))
            {
                listener.Prefixes.Add(Prefix.Remove(Prefix.Length - "/announce/".Length) + "/scrape/");
            }
            listener.Start();
            GetContextAsync(listener, token);
            RaiseStatusChanged(ListenerStatus.Listening);
        }
コード例 #17
0
        /// <summary>
        /// Starts listening for incoming connections
        /// </summary>
        public override void Start()
        {
            Cancellation?.Cancel();
            Cancellation = new CancellationTokenSource();

            var token    = Cancellation.Token;
            var listener = new UdpClient(OriginalEndPoint);

            token.Register(() => {
                LocalEndPoint = null;
                listener.Dispose();
            });

            LocalEndPoint = (IPEndPoint)listener.Client.LocalEndPoint;

            ReceiveAsync(listener, token);
            RaiseStatusChanged(ListenerStatus.Listening);
        }
コード例 #18
0
        private void Start()
        {
            if (Active)
            {
                Cancellation.Cancel();
                Task.WaitAll(Jobs.Values.ToArray());
            }

            Jobs.Clear();
            Cancellation = new CancellationTokenSource();

            foreach (var prefix in Services.Keys)
            {
                var task = new Task(ProcessCommand, prefix);

                Jobs.Add(prefix, task);
                task.Start();
            }
        }
コード例 #19
0
        /// <summary>
        /// Calls <see cref="TorrentManager.StopAsync()"/> on <see cref="Manager"/> and unregisters
        /// it from the <see cref="ClientEngine"/>. This will dispose the stream returned by the
        /// most recent invocation of <see cref="CreateHttpStreamAsync(ITorrentFileInfo)"/> or
        /// <see cref="CreateStreamAsync(ITorrentFileInfo)"/>.
        /// </summary>
        /// <returns></returns>
        public async Task StopAsync()
        {
            if (!Active)
            {
                throw new InvalidOperationException("The StreamProvider can only be stopped if it is Active");
            }

            if (Manager.State == TorrentState.Stopped)
            {
                throw new InvalidOperationException(
                          "The TorrentManager associated with this StreamProvider has already been stopped. " +
                          "It is an error to directly call StopAsync, PauseAsync or StartAsync on the TorrentManager.");
            }

            Cancellation.Cancel();
            await Manager.StopAsync();

            await Engine.Unregister(Manager);

            ActiveStream.SafeDispose();
            Active = false;
        }
コード例 #20
0
        /// <inheritdoc />
        /// <summary>
        /// Dispose this evaluator and all system resources used by this evaluator.
        /// If a load task is in progress, it will be cancelled and disposed asynchronously.
        /// </summary>
        public void Dispose()
        {
            // unsubscribe from events
            _entities.Moved   -= EntitiesOnMoved;
            _entities.Changed -= EntitiesOnChanged;
            _entities.Deleted -= EntitiesOnDeleted;

            // stop watching file changes
            _fileWatcher.Dispose();

            // cancel current loading operation
            Cancellation.Cancel();
            LoadTask.ContinueWith(parent =>
            {
                Cancellation.Dispose();
                foreach (var group in _backBuffer)
                {
                    group.Dispose();
                }
                _backBuffer  = null;
                _frontBuffer = null;
            });
        }
コード例 #21
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     Cancellation?.Cancel();
 }
コード例 #22
0
 public S3UploadsUploadBatch()
 {
     CancelCommand = new Command(() => { Cancellation?.Cancel(); }, () => Cancellation != null);
 }
コード例 #23
0
 public override void Dispose()
 => Cancellation.Cancel();
コード例 #24
0
 public void Dispose()
 {
     Cancellation.Cancel();
     ProgressController?.Close();
     Cancellation?.Dispose();
 }
コード例 #25
0
 public void Stop()
 {
     Cancellation.Cancel();
 }
コード例 #26
0
 public override void Stop()
 {
     Cancellation?.Cancel();
     RaiseStatusChanged(ListenerStatus.NotListening);
 }
コード例 #27
0
 public void CancelAll()
 {
     Cancellation.Cancel();
 }
コード例 #28
0
ファイル: Mode.cs プロジェクト: zjklee/monotorrent
 public void Dispose()
 {
     Cancellation.Cancel();
 }
コード例 #29
0
 public void Stop()
 {
     Cancellation?.Cancel();
     Cancellation = null;
 }
コード例 #30
0
        async Task Scan()
        {
            addressListView.Items.Clear();
            var count = 0;

            var stopwatch = Stopwatch.StartNew();

            Invoke((MethodInvoker)(() =>
            {
                readyToolStripStatusLabel.Text = ScanState.Scanning.ToString(count);
                Text = Title + " (検索中...)";
            }));

            var items = new Dictionary <ulong, ListViewItem>();

            var query = GetQuery();

            if (query == null)
            {
                return;
            }

            Watches = await MemoryScanner.FindMatches(query, exclusions : Exclusions, handler : (address, found) =>
            {
                BeginInvoke((MethodInvoker)(() =>
                {
                    var c = Interlocked.Increment(ref count);
                    Text = $"{Title} (検索中: {c})";
                    readyToolStripStatusLabel.Text = ScanState.Scanning.ToString(c);
                    items[address] = addressListView.Items.Add(new ListViewItem(new[] {
                        address.ToString("X8"), "", found.ToString()
                    }));
                }));
            });

            stopwatch.Stop();

            Invoke((MethodInvoker)(() =>
            {
                Text = $"{Title} ({Watches.Count})";
                readyToolStripStatusLabel.Text = ScanState.Complete.ToString(Watches.Count) + " (" + stopwatch.ElapsedMilliseconds + " ms)";
            }));

            Cancellation?.Cancel();
            Cancellation = new CancellationTokenSource();
            await MemoryScanner.Watch(Watches, 500, Cancellation.Token, t : query, handler : (k, v) =>
            {
                Invoke((MethodInvoker)(() =>
                {
                    if (items.ContainsKey(k))
                    {
                        items[k].SubItems[1].Text = v.ToString();
                    }
                    else
                    {
                        items[k] = addressListView.Items.Add(new ListViewItem(new[] {
                            k.ToString("X8"), v.ToString(), v.ToString()
                        }));
                    }
                }));
            });
        }