title: Can you stop a task when using aspx pages?
body: <p>How to stop and start a long running <code>Task</code> from an aspx page? I know how to stop a task with <code>CancellationTokenSource</code> in C#. In a windows form and a console app. But cannot seem to get it work on an aspx page. Is it even possible? I'm pretty sure because the page is posting the UI thread is lost.  Below is an example of a windows form project.</p>
  <pre><code>private async void btnGetDataAwait_Click(object sender, EventArgs e)
  {
     tokenSource = new CancellationTokenSource();
     try
     {
        btnGetDataAwait.Enabled = false;
        List&lt;Person&gt; people = await repo.Get(tokenSource.Token);
        foreach (var person in people)
        {
           listBox1.Items.Add(person);
        }
        btnGetDataAwait.Enabled = true;
     } 
     catch(OperationCanceledException ex)
     {
        MessageBox.Show(ex.Message, &quot;TASK CANCELED&quot;);
     }
     catch(Exception ex)
     {
        MessageBox.Show(ex.Message, &quot;EXCEPTION&quot;);
     }
  }
  </code></pre>
  <p>If your task was in an endless loop, on purpose, how can you grab the same thread/task and stop it?</p>