title: Asynchronous calls to Oracle DB using ADO.NET
body: <p>I am trying to perform multiple database calls using async and await features available in .NET Framework 4.5. This is the first time I am implementing this feature. </p>
  
  <p>if each query is taking 7 seconds, it used to take 35 seconds(5 queries * 7 seconds). With below implementation, I was expecting it should fetch and populate controls in asp page in close to 7-9 seconds. However, it is still taking 35 seconds, proving me the synchronous behavior.</p>
  
  <p>can someone please help me where I am going wrong with this below asynchronous implementation.</p>
  
  <p>I appreciate on any inputs, I have been breaking my head around this since couple of days</p>
  
  <pre><code>    protected void Page_Load(object sender, System.EventArgs e)
      {
          RegisterAsyncTask(new PageAsyncTask(FillControlsAsync));
      }
  
      public async Task FillControlsAsync()
      {
           Task[] tasks = new Task[]{
           PopulateControlTask(query1, "controlID1"),
           PopulateControlTask(query2, "controlID2"),
           PopulateControlTask(query3, "controlID3"),
           PopulateControlTask(query4, "controlID4"),
           PopulateControlTask(query5, "controlID5")
          });
  
          await Task.WhenAll(tasks);
      }
      public async Task PopulateControlTask(string query, string control)
      {
         await Task.Run(() =&gt;
             {
                 DataSet ds;
                 OracleCommand cmd;
                 OracleDataAdapter da;
                 try
                 {
                     if (!Page.IsPostBack)
                     {
                         cmd = new OracleCommand(query, cn);
                         da = new OracleDataAdapter(cmd);
                         ds = new DataSet();
                         da.Fill(ds);
                         switch (control)
                         {
                             case "controlID1":
                                  //some custom code for control 1
                                  // like attaching the datasource to control.
                                 break;
                             case "controlID2":
                                 //some custom code for control 2
                                 break;
                              case "controlID2":
                              //some custom code for control 3
                              break;
                              case "controlID3":
                              //some custom code for control 4
                              break;
                              case "controlID4":
                              //some custom code for control 5
                              break;
                      }
                  }
              }
              catch(Exception e)
              {
                   //some error handling here
              }
          });
      }
  </code></pre>