-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TaskScheduler should be able to cancel pending tasks #24221
Comments
cc @stephentoub , Any thoughts on this? |
I'd need to think about it in more depth, but on the surface it seems reasonable. |
That's something I could have used. We have a custom task scheduler in our codebase, that is bound to the lifetime of a request, and should stop executing new work after the request timeouts. But as mentioned, since there's no way of cancelling the enqueued task, it means that some code could be waiting on them forever. |
During a review of the expected final state of a |
Canceling a
My belief is that we should not change this requirement. For example, consider: semaphoreSlim.WaitAsync().ContinueWith(t =>
{
// do something under semaphore and release
}); If the continuation task is enqueued onto a If the Please correct me if I'm wrong with any of that. |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
This issue will now be closed since it had been marked |
From @JeffCyr on November 22, 2017 18:48
Rationale
After a
Task
is enqueued withTaskScheduler.QueueTask(Task task)
, it is currently not possible to cancel or fail the task if theTaskScheduler
can't execute the task.This makes it hard to implement a disposable
TaskScheduler
becauseDispose
needs to block until all pending tasks are executed, which is not always possible, or have to leave the pending tasks uncompleted, which is not ideal either.Proposed API
Details
TrySetCanceled
andTrySetException
can only be called for aTask
assigned to thisTaskScheduler
. This is similar toTryExecuteTask
.TrySetCanceled
andTrySetException
are implemented with best effort. They will returnfalse
if the tasks is already running or canceled by aCancellationToken
.Pull Request
A PR with the proposed changes is available on my fork: JeffCyr/coreclr#1
Copied from original issue: dotnet/coreclr#15171
The text was updated successfully, but these errors were encountered: