418 questions
Best practices
3
votes
3
replies
87
views
C# CancellationToken across chain of api calls
I have the following application architecture:
FrontEnd → ApiServer 1 → ApiServer 2 → Database
So, the frontend calls a web server, which calls multiple API which make query on database.
What is the ...
0
votes
2
answers
60
views
Get data received before HttpClient request is cancelled
I'm trying execute an HTTP request to receive some data (for example as a stream), but with ability to cancel this request at any time. I've read about CancellationToken and use it for cancel request (...
-1
votes
1
answer
116
views
IsCancellationRequested taking a long time to update after Cancel()
I'm noticing some strange behaviour with CancellationTokenSource wherein when I call the Cancel() method, IsCancellationRequested takes some time to update.
I am not sure if this is the cause, but in ...
2
votes
0
answers
117
views
How to Cancel or Abort Livewire Requests on Navigation
In my Livewire project, I want to stop all previous requests when navigating to a new page. The issue arises when older requests are still loading, and if they result in a 500 error, it affects the ...
0
votes
1
answer
252
views
How to correctly handle Ctrl-C or SIGINT in an ASP.NET Core console application?
I have an ASP.NET Core console application, that runs a REST interface and a pool of websockets. When I press Ctrl-C in the console, it shuts down correctly, unless I have a WebSocket connected. That ...
0
votes
1
answer
97
views
How to stop API execution without a loop activity in the source code using c# API
I have to stop the API execution through the Cancellation Token, In my method no for loops to check every time the cancellation requests, how to achieve it. I am using .NET core API
I have tried the ...
1
vote
0
answers
76
views
.Net Kestrel - Take control over the shutdown process
I have a .Net service that functions as a bridge between RabbitMQ and another service.
Messages are received and forwarded; Replies are received and delivered to RabbitMQ.
Internally I have some ...
1
vote
1
answer
162
views
Strange CancellationToken behaviour
Im testing CancellationToken behaviour in my UserRepository. When I use cancellationToken from parameters and cancel query with postman this works without exception (and it really cancels query). It ...
1
vote
0
answers
213
views
How to Set a Timeout for Crystal Report Generation or Stop the Task After a Certain Period?
I'm facing an issue with Crystal Reports where, once the report generation starts, it blocks other tasks and does not stop even after a certain time. I want to implement a timeout feature, where the ...
0
votes
1
answer
106
views
Cancel if the same task is called runned by Task.Run
I have code like below. Simply run the while loop for a long time.
public void Test(){
var task1 = Task.Run(() =>
{
while(true){
// forever
}
}
}
When Test()...
0
votes
1
answer
116
views
gRPC send python cancellation from client to C# Server (via the C# ServerCallContext context)
I thought this would just be a quick and easy problem to solve, but alas it is not.
I'm trying to find a way of sending a "CancellationToken" from my python client implementation which ...
0
votes
1
answer
353
views
Do I need to use a cancellation token when running bulk ExecuteUpdateAsync?
I have the code below where I call a service to fetch data, then save the data in a list (transfers). Then I loop through each transfer to update a specific row in the DB.
QUESTIONS -
Do I need to ...
0
votes
1
answer
439
views
CancellationToken in controller function of .Net Core suddenly becomes true
I just came into a very strange issue regarding cancellationToken. The web API is developed using .Net Core and frontend is in Angular. 1 hour ago I try to develop more feature and before starting I ...
0
votes
1
answer
113
views
Thread.Abort alternatives
public void Read(string file)
{
_read ?? = new Thread(() => MethodA(file));
_read.Start();
}
private void CancelReading()
{
if (_read != null)
{
if (!_read.Join(100))
...
1
vote
0
answers
167
views
How can I give an ID to CancellationToken?
I have a system that links tokens received from different places. Then, it uses this merged token to perform some task. The final merged token can consist of 5 different tokens.
While the task is ...
1
vote
0
answers
148
views
Why is my BackgroundService getting cancelled?
I have a simple BackgroundService.
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
NotifyBase? ...
-2
votes
1
answer
185
views
Trying to learn cancellation tokens. Not sure why this does not work
So, I'm learning Cancellation tokens and I'm trying this example. The writeline is never working even if I cancel this method from the outside.
So how this works, is the initializeAsync, if it takes ...
1
vote
1
answer
132
views
How to solve: Anonymous function converted to a void returning delegate cannot return a value
I am trying to implement semaphore slim for a set of tasks that are meant to request some data to an external API. The data might have different formats, so the plan is to return HttpResponseMessage, ...
1
vote
0
answers
109
views
How to Send a Message on a WebSocket Before Task Cancellation in C#?
I have an asynchronous method (IPCameraMethod) that handles IP camera streams. It starts and cancels tasks which manage these streams via WebSockets. The tasks are started in a separate class, ...
4
votes
1
answer
841
views
Cancelling the token source does not work and Main function gets stuck in Console app
I wrote the following C# code in .NET 6 in a simple console application. It captures "Interrupt" signal (i.e. Ctrl+C) and signals cancellation token source to cancel its token.
Then in Main ...
0
votes
0
answers
144
views
How do I cancel a Task that I didn't create? [duplicate]
I have a Task returned from a third party. It does not give me the option to insert a cancellation token when constructing the task. Can I insert a cancellation token into a task after the fact?
...
2
votes
3
answers
971
views
How to cancel a task without passing a CancellationTokenSource in .NET?
I have some business logic that does some long calculations, returns a result and doesn't accept any CancellationTokenSources and, accordingly, doesn't check for it's isCancellationRequested property.
...
-2
votes
1
answer
282
views
CancellationToken - throw exception from Timer
I'm calling Class Library method within WPF app, using CancellationToken. Method exports data to Excel from Oracle, and sometimes operation takes too long or doesn't complete, so I tried with ...
1
vote
1
answer
619
views
Nested IAsyncEnumerable function requires EnumeratorCancellation attribute?
I'd like to know if I need to use EnumeratorCancellation when passing a cancellation token to my local function. I am thinking of using this code pattern often in the future:
public static ...
0
votes
0
answers
153
views
Task Queue with cancellation
I'm looking for a way to be able to queue up a number of tasks to be completed in order, one after the other. But also for the functionality that when a new task is added, anything in the current ...