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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:02:30+00:00 2026-05-10T22:02:30+00:00

I’m trying to get a user control working asynchronously, yet no matter what I

  • 0

I’m trying to get a user control working asynchronously, yet no matter what I do it continues to work synchronously. I’ve stripped it down to its bare minimum as a test web application. This would be the user control:

<%@ Control Language='C#' %> <script runat='server'>     SqlConnection m_oConnection;     SqlCommand    m_oCommand;      void Page_Load(object sender, EventArgs e)     {         Trace.Warn('Page_Load');         string strDSN = ConfigurationManager.ConnectionStrings['DSN'].ConnectionString + ';async=true';         string strSQL = 'waitfor delay '00:00:10'; select * from MyTable';          m_oConnection = new SqlConnection(strDSN);         m_oCommand = new SqlCommand(strSQL, m_oConnection);         m_oConnection.Open();          Page.RegisterAsyncTask(new PageAsyncTask(new BeginEventHandler(BeginHandler), new EndEventHandler(EndHandler), new EndEventHandler(TimeoutHandler), null, true));         Page.ExecuteRegisteredAsyncTasks();     }      IAsyncResult BeginHandler(object src, EventArgs e, AsyncCallback cb, object state)     {         Trace.Warn('BeginHandler');         return m_oCommand.BeginExecuteReader(cb, state);     }      void EndHandler(IAsyncResult ar)     {         Trace.Warn('EndHandler');         GridView1.DataSource = m_oCommand.EndExecuteReader(ar);         GridView1.DataBind();         m_oConnection.Close();     }      void TimeoutHandler(IAsyncResult ar)     {         Trace.Warn('TimeoutHandler');     } </script> <asp:gridview id='GridView1' runat='server' /> 

And this would be the page in which I host the control three times:

<%@ page language='C#' trace='true' async='true' asynctimeout='60' %> <%@ register tagprefix='uc' tagname='mycontrol' src='~/MyControl.ascx' %> <html>     <body>         <form id='form1' runat='server'>             <uc:mycontrol id='MyControl1' runat='server' />             <uc:mycontrol id='MyControl2' runat='server' />             <uc:mycontrol id='MyControl3' runat='server' />         </form>     </body> </html> 

The page gets displayed without errors, but the trace at the bottom of the page shows each control instance is processed synchronously. What am I doing wrong? Is there a configuration setting somewhere I’m missing?

  • 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. 2026-05-10T22:02:30+00:00Added an answer on May 10, 2026 at 10:02 pm

    Looks like I can answer my own question. The user control should not be calling Page.ExecuteRegisteredAsyncTasks. By doing that, the control was adding the async task, running it, and waiting for it to complete.

    Instead, each instance of the user control should call only Page.RegisterAsyncTask. After each control instance has done this the page automatically calls RegistereAsyncTask running all three registered async tasks simultaniously.

    So here is the new user control:

    <%@ Control Language='C#' %> <script runat='server'>     SqlConnection m_oConnection;     SqlCommand    m_oCommand;      void Page_Load(object sender, EventArgs e)     {         Trace.Warn(ID, 'Page_Load - ' + Thread.CurrentThread.GetHashCode().ToString());         string strDSN = ConfigurationManager.ConnectionStrings['DSN'].ConnectionString + ';async=true';         string strSQL = 'waitfor delay '00:00:10'; select * from TEProcessedPerDay where Date > dateadd(day, -90, getutcdate()) order by Date asc';          m_oConnection = new SqlConnection(strDSN);         m_oCommand = new SqlCommand(strSQL, m_oConnection);         m_oConnection.Open();          Page.RegisterAsyncTask(new PageAsyncTask(new BeginEventHandler(BeginHandler), new EndEventHandler(EndHandler), new EndEventHandler(TimeoutHandler), null, true));     }      IAsyncResult BeginHandler(object src, EventArgs e, AsyncCallback cb, object state)     {         Trace.Warn(ID, 'BeginHandler - ' + Thread.CurrentThread.GetHashCode().ToString());         return m_oCommand.BeginExecuteReader(cb, state);     }      void EndHandler(IAsyncResult ar)     {         Trace.Warn(ID, 'EndHandler - ' + Thread.CurrentThread.GetHashCode().ToString());         GridView1.DataSource = m_oCommand.EndExecuteReader(ar);         GridView1.DataBind();         m_oConnection.Close();     }      void TimeoutHandler(IAsyncResult ar)     {         Trace.Warn(ID, 'TimeoutHandler - ' + Thread.CurrentThread.GetHashCode().ToString());     } </script> <asp:gridview id='GridView1' runat='server' /> 

    And the unchanged page that creates three instances of the control:

    <%@ page language='C#' async='true' trace='true' %> <%@ register tagprefix='uc' tagname='mycontrol' src='~/MyControl.ascx' %> <html>     <body>         <form id='form1' runat='server'>             <uc:mycontrol id='MyControl1' runat='server' />             <uc:mycontrol id='MyControl2' runat='server' />             <uc:mycontrol id='MyControl3' runat='server' />         </form>     </body> </html> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.