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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:57:04+00:00 2026-06-10T18:57:04+00:00

How could I convert the method: static void DoWork(Action<bool> onCompleteCallback) { Task doWork =

  • 0

How could I convert the method:

static void DoWork(Action<bool> onCompleteCallback)
{            
    Task doWork = new Task( ()=>Thread.Sleep(2000) );

    Action<Task> onComplete = (task) => {
        onCompleteCallback(true); // should execute on the main thread
    };

    doWork.ContinueWith(onComplete, TaskScheduler.FromCurrentSynchronizationContext());
    doWork.Start();                        
}

to Async.

If I convert it to Async what will be the difference?

  • 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-10T18:57:06+00:00Added an answer on June 10, 2026 at 6:57 pm

    Part of the reason to use async and await is to avoid callbacks. By using the new async support, your method itself can return a Task (or Task<T>), and you can just use await on it, avoiding the need to pass in a callback entirely.

    If you wanted to use the new async/await setup, you’d write this as:

    static Task DoWork()
    {
         return Task.Run( () => /* Your work */ Thread.Sleep(2000) );            
    };
    

    The difference would actually be in how you call this. Instead of using a callback, you’d just write:

    await DoWork();
    // Do your callback work here - it'll automatically be mapped into the right sync context and happen after the above completes
    

    You could, of course, pass the callback in still, and write it as:

    static async Task DoWork(Action<bool> onCompleteCallback)
    {            
         await Task.Run( ()=>Thread.Sleep(2000) ); // Or use Task.Delay(2000) if you just want a pause...
         onCompleteCallback(true);
    };
    

    This just defeats the purpose (somewhat) of using the new support, as one of the main advantages is that you no longer need to pass around callbacks and turn your logic “inside-out”.

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

Sidebar

Related Questions

Anyone know of a nice efficient function that could convert, for example: HelloWorld -->
How could i convert this string 03/16/2012 03:22PMusing php to store in datetime format
How could I convert a VimOutliner file to Markdown? In other words, I how
I would like to ask how could I convert a string which inserted by
How could I merge / convert multiple PDF files into one large PDF file?
Could anyone please help me convert this code to vb.net, I have tried it
how could I trim and convert a string as following: string abc = 15k34
Could someone please help me to convert this String into a Map ... String
How can I convert xml to java so that it could read the xml
I'm trying to convert a string to an array of integers so I could

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.