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

  • SEARCH
  • Home
  • 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 8415365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:25:34+00:00 2026-06-10T01:25:34+00:00

I have defined the following Task var t = Task.Factory.StartNew( () => LongRunningMethod( cancellationToken

  • 0

I have defined the following Task

var t = Task.Factory.StartNew(
    () => LongRunningMethod( cancellationToken ),
    cancellationToken
);

t.ContinueWith(
    Callback,
    cancellationToken,
    TaskContinuationOptions.None,
    TaskScheduler.FromCurrentSynchronizationContext()
);

Inside the LongRunningMethod, I check if the cancellation token has a cancellation requested, and if so, I return from the method. That much works fine.

However, the Callback does not get called in this scenario. The callback does get called if I replace the second line above with

t.ContinueWith(
    x => Callback( x, cancellationToken ),
    TaskScheduler.FromCurrentSynchronizationContext()
);

In this situation, the task still thinks it ran to completion.

Why doesn’t the first call work? I was under the impression that TaskContinuationOptions.None means that the callback will get called regardless of the state of the thread.

I am cancelling the Task by calling:

_cancellationTokenSource.Cancel();

On a somewhat related note, having to pass around cancellation tokens seems like a major design flaw of the Task library.

  • 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-10T01:25:35+00:00Added an answer on June 10, 2026 at 1:25 am

    Your continuation task takes a CancellationToken which you cancel. This means that the continuation task, while unstarted, is being cancelled. Don’t pass that token to thing which you don’t want to cancel.

    CancellationToken is meant to cancel the whole graph of actions at once. You can exclude stuff from cancellation by not passing the token.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following test defined in a psake build script: task package -depends
I have a cron task setup to run the following: php /var/www/vhosts/examplesite.com/index.php cron processCategoryItemCount
I have a build task in rake defined with the following dependencies: desc 'Builds
I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid
I have defined following in a ResourceDictionary: <DockPanel x:Key=errorDisplay LastChildFill=False> <Border Background=Red DockPanel.Dock=Top> <TextBlock
In my .htaccess file I have defined following rule, RewriteRule t/([^.]+)/$ /videos/tag.php?tag=$1 [QSA] The
I have defined the following class using COM to use the IGroupPolicyObject using C#.NET:
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )
I have defined the following struct in C: typedef struct point{ float x; float
I have defined the following Interface [ServiceContract] public interface IHealthProducts { [OperationContract()] ResponseClass OrderSelfSignedHealthCertificate();

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.