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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:05:33+00:00 2026-05-27T04:05:33+00:00

Following this question , I am trying to implement an async method using the

  • 0

Following this question, I am trying to implement an async method using the TPL, and trying to follow TAP guidelines.

I want my async method to perform a callback when it’s finished. As far as I can see there are three ways I can do this.

1) Callback manually in my task delegate

public Task DoWorkAsync(DoWorkCompletedCallback completedCallback)
{
    return Task.Factory.StartNew(
    { 
        //do work

        //call callback manually
        completedCallback();
    });
}

2) Assign callback to task in task delegate

public Task DoWorkAsync(DoWorkCompletedCallback completedCallback)
{
    return Task.Factory.StartNew(
    { 
        //do work
    }
    ).ContinueWith(completedCallback); //assign callback to Task
}

3) Assign callback to task in caller

public Task DoWorkAsync()
{
    return Task.Factory.StartNew(
    { 
        //do work
    });
}

public void SomeClientCode()
{
    Task doingWork = DoWorkAsync();
    doingWork.ContinueWith(OnWorkCompleted);
}

My gut feeling is that 3 is more correct, because it decouples the callback from the method, and means that client code can manage the task any way it sees fit (using callbacks, polling etc), which seems to be what Tasks are all about. However, what happens if DoWorkAsync() completes its work before the client code hooks up its callback?

Is there a generally accepted way to do this or is it all too new?

Is there any advantage of doing 2) over 1)?

  • 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-05-27T04:05:33+00:00Added an answer on May 27, 2026 at 4:05 am

    The generally accepted way is 3.

    Users of TPL generally know that they can continue a Task with ContinueWith. 1 and 2 provide the same functionality, but with a non-standard interface; the user has to figure out what the delegate parameter means and what to pass e.g. if they don’t want to continue — all that while the method still returns a Task that can be continued in the standard way.

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

Sidebar

Related Questions

Following up from this question , I'm trying to implement an unobtrusive confirm dialog.
Following on from this question...I'm trying to unit test the following scenario: I have
Following on from this question , I now want to know how to stop
I'm trying to implement the following feature: I want just one css file to
I'm trying to implement the following method: void Ball::DrawOn(Graphics g); The method should draw
Edit : This is a mostly Rails question I'm trying to implement instant payment
In the following code i am trying to implement inheritance and polymorphism properties,My question
I am trying to implement the same code that was mentioned in this question
Following this question: Good crash reporting library in c# Is there any library like
Following on from this question what would be the best way to write 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.