Questions tagged [cancellation-token]

The CancellationToken is a .NET struct that enables cooperative cancellation of synchronous or asynchronous methods.

366 questions
0
votes
1 answer

Task.RunSynchronously() doesn’t care about CancellationToken

I want to execute a 3rd party function on the current thread (to avoid overhead) but want to be able to use a CancellationToken to interrupt the function at any time. That's how I create and run the task: var task = new Task(proc, cts.Token); // cts…
0
votes
1 answer

.NET 4.5.1 Track all Tasks for Cancellation?

5 unrelated class instances do Task.Run() to start 1-4 instances that "do stuff". Each Task has a CancellationToken. What is a cool or smart way to have another object stop all of those spawned Tasks without touching/affecting their spawning…
Snowy
  • 5,942
  • 19
  • 65
  • 119
0
votes
1 answer

Cancellation token and thread not working

I want to cancel a thread and and run another one just after. Here is my code: private void ResetMedia(object sender, RoutedEventArgs e) { cancelWaveForm.Cancel(); // cancel the running thread …
0
votes
1 answer

Sending a Cancellation Token in a Task

I have an async method that I want to be able to cancel that is currently called string html = await Html.WebClientRetryAsync(state); I have been trying to figure out the syntax to be able to call this method passing it a CancellationToken.…
Harrison
  • 3,843
  • 7
  • 22
  • 49
0
votes
1 answer

ThreadPool.RegisterWaitForSingleObject(CancellationToken.WaitHandle): will it ever finish?

I am implementing code from the accepted answer on this question. Now I'm having a problem looking like threads are being left open: the application never finishes. I think this may be caused by the bottom one of the two occurences of…
0
votes
1 answer

NotificationHub RegisterNativeAsync with CancellationToken

I have a WP app that use NotificationHub. To register the user, I call RegisterNativeAsync. However, some users having slow connection raise to me that the loading is very long. Is it possible to pass a CancellationToken when calling…
0
votes
1 answer

Why after adding a header to HttpClientRequestMessage CancellationToken.IsCancellationRequested changes to true

I use custom HttpClientHandler to authorize test if it is not authorized. Windows Store Unit Test App project type is used using Microsoft.WindowsAzure.MobileServices; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using…
Andrii
  • 1,081
  • 1
  • 11
  • 24
0
votes
2 answers

Async Repository & CancellationToken

We're moving to .NET 4.5 and I'm considering adding async to my repositories: interface IRepository { T Find(int id); Task FindAsync(int id); IEnumerable FindAll(); Task> FindAllAsync(); …
n8wrl
  • 19,439
  • 4
  • 63
  • 103
0
votes
1 answer

MVC cancel task using cancellation token

I would like to cancel a task using a cancellation token as described here: http://msdn.microsoft.com/en-us/library/dd997396.aspx. The only difference is that: I would like to start a task when I browse to a specific controller/Action, and cancel…
ShaneKm
  • 20,823
  • 43
  • 167
  • 296
-1
votes
1 answer

Stop a Task with a CancelationToken

I have a class that represents a custom Task. This class has an Execution method that returns the IEnumerable of all the inside yield return statement, and a Start method that calls the enumerable, thus executing the lazy code. My problem is…
Bloom Dee
  • 37
  • 7
-1
votes
1 answer

CancellationToken CanBeCanceled always true with HttpClient

I created a default Blazor WASM ASP.NET hosted app. On WeatherForecastController Get method i added the parameter CancellationToken cancellationToken: [HttpGet] public IEnumerable Get(CancellationToken cancellationToken) Now, from…
-1
votes
1 answer

IsCancellationRequested = true and go to exception. How to get all respose from API?

I am working on .net core 3.1. I am trying to use https://services.timeanddate.com/ API. when debuggeing I got IsCancellationRequested = true and go to exception. The request that was canceled that line below: using var response = await…
-1
votes
3 answers

Will having a delay between canceling and disposing a CancellationTokenSource provide any assurance that IsCancellationRequested will be set to true?

C# Windows UWP project I have implemented CancellationTokenSource and CancellationToken in an async method that calls another method. This method contains a while loop which maintains the value of a bool variable as true until the token source is…
-1
votes
3 answers

C# - Whats wrong with my CancellationToken?

Pls look at this code, running on .Net Core 2.0: var src = new CancellationTokenSource(5000); var token = src.Token; var responseTask = await Task.Factory.StartNew(async () => { //Uncomment bellow to reproduce locally //await…
Leonardo
  • 10,737
  • 10
  • 62
  • 155
-1
votes
2 answers

How to correct cancel Task with Event Handler

Sorry for bad english. In my project i have two Task. One for decoding data from IP camera and fire frame ready event to UI. And other to watch the camera is not offline. If the camera is offline, it throw Error event handler to UI thread. UI…
1 2 3
24
25