/// <summary> /// Stops the running application /// </summary> /// <returns></returns> public async Task StopAsync() { Cancellation.Cancel(); await Startup.ShutdownAsync(); Running = false; }
public Task CancelTask() { return(Task.Run(() => { Cancellation.Cancel(); })); }
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(); }
public void Cancel() { if (!_isDisposed) { Cancellation.Cancel(); } }
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(); }
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; }
private void buttonCancel_Click(object sender, EventArgs e) { Cancellation cancellation = _fileTransferCancellation; if (cancellation != null) { cancellation.Cancel(); buttonCancel.Enabled = false; } }
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(); }
public virtual void Stop() { Trace.WriteLineIf(Tracing.Is.TraceVerbose, string.Empty); if (null == Timer) { return; } Timer.Dispose(); Timer = null; Cancellation.Cancel(); }
/// <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(); }
/// <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(); }
/// <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(); }
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(); } }
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); } }
/// <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); }
/// <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); }
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(); } }
/// <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; }
/// <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; }); }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { Cancellation?.Cancel(); }
public S3UploadsUploadBatch() { CancelCommand = new Command(() => { Cancellation?.Cancel(); }, () => Cancellation != null); }
public override void Dispose() => Cancellation.Cancel();
public void Dispose() { Cancellation.Cancel(); ProgressController?.Close(); Cancellation?.Dispose(); }
public void Stop() { Cancellation.Cancel(); }
public override void Stop() { Cancellation?.Cancel(); RaiseStatusChanged(ListenerStatus.NotListening); }
public void CancelAll() { Cancellation.Cancel(); }
public void Dispose() { Cancellation.Cancel(); }
public void Stop() { Cancellation?.Cancel(); Cancellation = null; }
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() })); } })); }); }