Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Looks like I can answer my own question. The user control should not be calling <code>Page.ExecuteRegisteredAsyncTasks</code>. By doing that, the control was adding the async task, running it, and waiting for it to complete.</p> <p>Instead, each instance of the user control should call only <code>Page.RegisterAsyncTask</code>. After each control instance has done this the page automatically calls <code>RegistereAsyncTask</code> running all three registered async tasks simultaniously.</p> <p>So here is the new user control:</p> <pre><code>&lt;%@ Control Language="C#" %&gt; &lt;script runat="server"&gt; 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 &gt; 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()); } &lt;/script&gt; &lt;asp:gridview id="GridView1" runat="server" /&gt; </code></pre> <p>And the unchanged page that creates three instances of the control:</p> <pre><code>&lt;%@ page language="C#" async="true" trace="true" %&gt; &lt;%@ register tagprefix="uc" tagname="mycontrol" src="~/MyControl.ascx" %&gt; &lt;html&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;uc:mycontrol id="MyControl1" runat="server" /&gt; &lt;uc:mycontrol id="MyControl2" runat="server" /&gt; &lt;uc:mycontrol id="MyControl3" runat="server" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload