Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:02:24+00:00 2026-06-11T10:02:24+00:00

I am looking into adding cancellation support to awaitable extension methods in the AsyncUI

  • 0

I am looking into adding cancellation support to awaitable extension methods in the AsyncUI and WinRT XAML Toolkit libraries. It seems like the base Task class does not have a built-in Cancel() method or event and relies on cancellation tokens that my tasks would need to check for periodically. I think does not make sense in my UI scenarios, since my tasks are generated using the TaskCompletionSource and I would like to cancel the tasks on the UI thread in response to events instead of running a loop on a thread pool thread and checking for a token.

My tasks currently complete when a UI event happens – like a Storyboard completing or a button being clicked, so if I want to support cancellation – I need to respond to a cancellation request by unsubscribing from events and doing other cleanup like stopping an animation .

I am thinking of creating some sort of CancellableUITask base class instead of using the TaskCompletionSource, so I could expose a Cancel() method that the consumer of my task could call (e.g. to stop an awaited animation in response to a button click) and something like a virtual OnCancellationRequested() method that my storyboard awaiter task could override to perform cleanup.

Does it make sense? What would be the best way to accomplish what I am describing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:02:25+00:00Added an answer on June 11, 2026 at 10:02 am

    Your tasks would not need to check periodically for cancellation – that is just the most common way of doing things. If your tasks are event-driven, then you can register a handler against the CancellationToken that will be called when it is cancelled. See CancellationToken.Register.

    So your code might look something like this:

    public Task DoSomethingAsync(CancellationToken cancellationToken = default(CancellationToken))
    {
        var tcs = new TaskCompletionSource();
    
        if (cancellationToken.CanBeCanceled)
        {
            // register for notification of cancellation
            cancellationToken.Register(...);
        }
    
        // set up other handlers and what-not
    
        return tcs.Task;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking into adding a chat feature on my site (it's somewhat like a
I am looking into adding accessibility support to a WPF application. This article describes
I am looking into adding accessibility support to a WPF application. This article describes
I am looking into adding unit tests at work. I used MbUnit in the
I'm looking into adding some unit tests for some classes in my data access
I looking into making a kind of robot testing browser. Like Selenium, but one
I'm looking into adding a jquery modal popup to my mvc project. I have
I am looking into adding RSS feeds to one of my Django apps and
I'm looking into adding scripting to my C# application. I've been debating between Lua
Recently I've been looking into adding a simple HTML5 drag and drop to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.