Allow ShowAndWaitAsync task to be cancellable (Using CancellationToken)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 9.6k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem? Please describe
Basically, I'm writing a multitask await scenario.
I'm trying to use a standard Task, and Task<IDialogControl.ButtonPressed>.
The objective is use the popup to block interactions until either, the Task is finished or the popup button is pressed.
The approach I use is wait for either task to be finished and cancel the other.
I can't cancel the ShowAndWaitAsync Task.
Describe the solution you'd like
Let the ShowAndWaitAsync take a cancellation token to allow cancelling the interaction.
Describe alternatives you've considered
I tried to do this with events and it's not a viable workaround.
I'm just using a single function to wait until "Task finishes or Click happens".
Additional context
Example code which adds context for the desired execution.
CancellationTokenSource _myCancellationTokenSource = new CancellationTokenSource();
Task<IDialogControl.ButtonPressed> popupInteractedTask = _dialogControl.ShowAndWaitAsync("Blocked", "Interact to unblock" /*, _myCancellationTokenSource.Token */);
Task taskEndedTask = /* arbitrary task which takes _myCancellationTokenSource.Token */;
// Create an array of tasks
Task[] tasks = new Task[] { popupInteractedTask, taskEndedTask };
// Task that waits for any of the tasks on the array to end
Task<int> resultWaitTask = new Task<int>(() =>
{
return Task.WaitAny(tasks);
});
resultWaitTask.Start();
// Non-blockingly wait until any task ended
await resultWaitTask;
// Do cleanup of the non-finished task
// This works fine for the taskEndedTask task, but not for popupInteractedTask.
_myCancellationTokenSource.Cancel();
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the ShowAndWaitAsync entry point and trace how the popup interaction task completes and is cleaned up. Done means the method accepts the requested CancellationToken and cancellation can end the interaction, supporting the example's task-completion-or-button-press scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100