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 9201097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:55:23+00:00 2026-06-17T22:55:23+00:00

My C# Task is getting canceled, but not by me. I don’t get a

  • 0

My C# Task is getting canceled, but not by me. I don’t get a stacktrace and I can’t figure out where the problem occurs.

My task invocation looks like this:

var t = Task<Boolean>.Factory.StartNew(() =>
    {
        Boolean bOk = DoSomthingImportant();
        return bOk;
    }, TaskCreationOptions.AttachedToParent)
    .ContinueWith<Boolean>((theTask) =>
    {
        var reason = theTask.IsCanceled ? "it was canceled" : "it faulted";
        Debug.WriteLine("Error: Task ended because " + reason + ".");
        ... log the exception to one of my objects...
        return false;
    }, TaskContinuationOptions.NotOnRanToCompletion);

I want the continuation task to run if the task faulted or was canceled, but not if it ran okay.
The continuation is never executed.

Later on my program catches an AggregateException which is wrapping a TaskCanceledException.

My other major interaction with my tasks is to call WaitAny(taskArray, timeout) until I have no more tasks to start, then call WaitAll with no timeout until the last task is done.

Could WaitAny with a timeout cause a cancellation? Why didn’t my continuation get called?

This is only my second brush with the Task library, so I am clueless.

UPDATE:

I found this SO question: How to propagate a Task’s Canceled status to a continuation task.
One error in my code above (but not the cause of the Cancelation) is that I assumed that the Continuation tasks status was the same as the original task’s status. In fact you have to do some work to get the one from the other, as the other post describes.

UPDATE 2:

Brian: Thanks for the documentaion reference. I had searched high and low for alternate causes of a Task being canceled, but missed these words:

“If you are waiting on a Task that transitions to the Canceled state,
a Task (wrapped in an AggregateException) is manufactured and thrown.
Note that this exception indicates successful cancellation instead of
a faulty situation. Therefore, the Task’s Exception property returns
null.”

  • 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-17T22:55:24+00:00Added an answer on June 17, 2026 at 10:55 pm

    You’re waiting on the continuation and since the original task ran to completion the continuation task was cancelled. This behavior is covered in the documentation.

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

Sidebar

Related Questions

Im trying to run launch4j as a build task on macosx but im getting
For some reasons I cannot get anything to come out of task_for_pid() I can't
I keep getting the message 'Activity not started, its current task has been brought
I am getting following while doing ant build: Build\build.xml:247: Problem: failed to create task
I have to write a rails task for getting files from s3 bucket but
I'm trying to extend Task class, but I get two different errors depending how
I'm trying to run a task on app engine, but i'm getting the following
Iam getting an EXC_BAD_ACCESS all the time and I cannot figure out why... Simple
My actual task is getting completed however I am not getting any increase in
This is the error I'm getting: Task not supported by 'mysql2' /Users/me/.rvm/gems/ruby-1.8.7-p352@project/gems/rails-2.3.8/lib/tasks/databases.rake:380 Here is

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.