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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:48:42+00:00 2026-06-02T19:48:42+00:00

I am doing probes with the new TAP pattern, using Task and CTP to

  • 0

I am doing probes with the new TAP pattern, using Task and CTP to implement async methods.

I have the following code:

private async void btnAsync01_Click(object sender, RoutedEventArgs e)
        {
            UpdateTxtLog("Enter in button Async01: " + System.DateTime.Now);
            double result = await method01Async();
            UpdateTxtLog("exit in button Async01: " + System.DateTime.Now);
            UpdateTxtLog("result: " + result.ToString());
        }

Is the button of the GUI that let me test async methods.

I can have the following implementations of the method01Aync.

First:

private async Task<double> method01Async()
        {
              return await Task.Factory.StartNew<double>(slowMethod);
        }


private double slowMethod()
{
            double doubleDummy = 0;
            for (double i = 0; i < 1000000000; i++)
            {
                doubleDummy++;
            }
            return doubleDummy;
}

Second

private Task<double> method01Aync()
{
return Task.Factory.StartNew<double>(() =>
            {
                //O métodos auxiliares lentos... etc.
                double doubleDummy = 0;
                for (double i = 0; i < 1000000000; i++)
                {
                    doubleDummy++;
                }
                return doubleDummy;
            });
}

Third

private Task<double> method01Aync()
{
            return TaskEx.Run<double>(() =>
            {
                double doubleDummy = 0;
                for (double i = 0; i < 1000000000; i++)
                {
                    doubleDummy++;
                }
                return doubleDummy;
            });
}

Fourth
private Task method01Async()
{
return TaskEx.Run(slowMethod);
}

Fith

private Task<double> method01Async
{
return TaskEx.Run<double>(() =>
            {
                return metodoLento();
            });
}

My results are that the implementation 1 and 4 take me 22s aprox. to finish meanwhile the other two takes 5s. Why does exist this difference? In the implementation 1 and 4, only use an auxiliary method with the same code with the loop.

I have notice that if I use the slowMethod() as parameter of the constructor of the Task is very slow and if I use delegates in the TaskEx or in task Factory is fast. Why does it happen this? Which is the difference?

Which is the difference of using Task.Factory or TaskEx.Run?

What is the best practice to use async with task with the TAP pattern?

  • 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-02T19:48:45+00:00Added an answer on June 2, 2026 at 7:48 pm

    Performance testing is a tricky subject.

    Trying to ‘trick’ the compiler into thinking there’s work to be done when you’re just using a loop and counter is likely to cause inconsistent behaviour.

    This is before mentioning the fact that there’s no warm up before the timing, this is likely done with Debug mode on, and the timing code itself isn’t shown.

    All in all – assume that minor changes in the way you write how you call a long running process in the real world will not affect your performance materially.

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

Sidebar

Related Questions

Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing some code reviews lately I came across a number of classes that have
I have a simple method in my code which looks like the following: -
Doing my first SL4 MVVM RIA based application and i ran into the following
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
Doing some jquery animation. I have certain divs set up with an attribute of
Doing code analysis of the project and get the message Reference-counted object is used
Doing this: var _partsCatalog = new DirectoryCatalog(directoryName);//Fully qualified path to our bin folder var
There are different opinions on the meaningfulness of testing of private methods, e.g., here
I have been using Java for a long time, and for quite some time

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.