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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:43:49+00:00 2026-06-07T22:43:49+00:00

I made a simple async method to call an SQL stored procedure asynchronously. In

  • 0

I made a simple async method to call an SQL stored procedure asynchronously.

In my console program, I am calling this method 1000 times in a loop, and sleep for 1ms (Thread.Sleep) between each call.
I start a StopWatch before entering the loop, and stop it when exiting the loop, and display the time spent in the loop.

On my development machine (Win7 – VS 2012 RC), I can see what I was expecting to see :

Completed in 1006 ms

This seems logical, considering that the call to the async method returns almost immediately (when reaching the first await keyword), so there is just a small overhead (6ms) incured while executing the code before the await.

However when I run the exact same code on a server machine (Win2008 R2 SP1) on which I have installed .NET Framework 4.5 RC the code is running fine however the execution time is far from the one I am expecting, in no comparison with the one obtained when running the program on my development machine :

Completed in 15520 ms

Meaning that somehow the async method being called is not really called asynchronously and the first await seems to somehow block ?

Here is the code of the async method I am calling :

public async void CallSpAsync()
{
  var cmd = new SqlCommand("sp_mysp");
  {  
     var conn = new SqlConnection(connectionString);
     {
       cmd.Connection = conn;
       cmd.CommandType = CommandType.StoredProcedure;

       [...Filling command parameters here - nothing interesting...]

       await cmd.Connection.OpenAsync();                    
       await cmd.ExecuteNonQueryAsync();

       cmd.Dispose();
       cmd.Connection.Dispose();
     }
  }
}

And here is the main program testing code (loop) :

Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000; i++)
{
   CallSpAsync();
   Thread.Sleep(1);
}
sw.Stop();

I am running the exact same executable (console program compiled in Release) on both machines.

I am tyring to figure out why the method is not truly called asynchronously when running the program on the server machine.

Any idea ?

Thanks !

EDIT

The problem has nothing to do with async/await which is working just fine, but is due to the timer resolution (used by StopWatch) on the server being 15 time less than on my workstation. The code is not running slower at all, it’s just the resolution of the timer which is leading to incorect elapsed time computation.

See answer from James Manning below.

  • 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-07T22:43:51+00:00Added an answer on June 7, 2026 at 10:43 pm

    This might be a function of the timer resolution on the server machine. Check the ClockRes utility. You can get some more details in my comment on High accuracy DateTime.UtcNow.

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

Sidebar

Related Questions

I made a simple ball bouncing program with VC++. the goal of this program
I have made simple encryption/decryption method in php that I'm trying to move to
I made simple procedure just to demonstrate CREATE PROCEDURE `demo`(demo_int int) BEGIN DECLARE minid
I'm learning java and I have made simple program that simply reads value from
I made simple plugin and i would like to work this plugin only below
I made simple python program to generate big text file: import sys import random
I made simple email in wordpress but it would only send email to the
hi i've got question i've made simple form with attachment input and i want
Visual Studio 2008 (vb.net) I made simple anivirus but when I make Full scan
OK, I have made simple rectangular using OpenGL, and it looks pretty simple glNormal3f(0.0f,

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.