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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:17:04+00:00 2026-06-11T08:17:04+00:00

My class has a method which produces a Task<int> object using a TaskCompletionSource<int> .

  • 0

My class has a method which produces a Task<int> object using a TaskCompletionSource<int>. Then it does some asynchronous operations and sets the result. I need to know whether I can trust the task’s ContinueWith method or not:

public Task<int> CalculateAsync()
{
    var source = new TaskCompletionSource();
    DoSomeAsyncStuffAndSetResultOf(source);

    source.Task.ContinueWith(t => Console.WriteLine("Is this reliable?"));
    return source.Task;
}

Can the caller of CalculateAsync method do something with the produced task and prevent its continuation from running?

  • 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-11T08:17:06+00:00Added an answer on June 11, 2026 at 8:17 am

    You can pass a CancellationToken into various overloads of ContinueWith… that would be the most idiomatic way of just cancelling the continuation, IMO.

    I don’t think there’s anything you can do to the parent task to cancel continuations. I kinda hope not, anyway…

    EDIT: Okay, it sounds like you’re trying not to let that happen. No, you don’t need to worry. Unless the caller can somehow make the task run forever without ever completing, being cancelled or faulting, the continuation will run.

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

Sidebar

Related Questions

I've got following problem: (c#) There is some class (IRC bot), which has method,
I have an object class called BOM. It has a method, getChildItem() which returns
I have a class that has an output() method which returns a matplotlib Figure
I have a class with static method which has a local static variable. I
I have a controller which has a method called history class UsersController < ApplicationController
In .NET 4.0+, a class SortedSet<T> has a method called GetViewBetween(l, r) , which
Imagine you have class A which has code which runs as method M. And
Assume someClass is a class defined in C# with some method int doSomething(void) ,
In the Sequel ORM for Ruby, the Dataset class has an all method which
I have 3 ASP.NET pages. Each has its own GetSearchResult method, which produces a

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.