title: Unable to cancel Async/Awaiting call on button click
body: <p>I am unable to cancel async/await call on cancel button click. I want to cancel query if it will take long time to load data in grid. I am new to use async/await method and referred many examples, but unable workout if. Pleas have look on my below code and Please help. thanks</p>
  
  <pre><code>    namespace MyFirstAsync
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
          CancellationTokenSource cts ;
          private async void btnExecute_Click(object sender, EventArgs e)
          {
              cts = new CancellationTokenSource();
              try
              {
                  string connectionString = "Data Source=G50-80;Initial Catalog=HPSF_Compdb;User ID=sa;Password=sql@2012";
                  string sqlQuery = "select top 900000 * from requestevent.result";
                  SqlConnection conn = new SqlConnection(connectionString);
                  SqlCommand cmd = new SqlCommand(sqlQuery, conn);
                  await conn.OpenAsync(cts.Token);
                  SqlDataReader reader = await cmd.ExecuteReaderAsync(cts.Token);
                  DataTable dt = new DataTable();
                  //cts.Cancel();
                  await Task.Run(() =&gt; dt.Load(reader), cts.Token);
                  gvData.Invoke(new gvDelegate(UpdateDataToGrid), new object[] { dt });
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
              }
  
          }
  
          public delegate void gvDelegate(DataTable dt);
          public void UpdateDataToGrid(DataTable dt)
          {
              gvData.DataSource = dt;
          }
  
  
  
          private void btncancel_Click(object sender, EventArgs e)
          {
              cts.Cancel();
          }
  
  
  
      }
  }
  </code></pre>