Cancel a task without checking for cancellation token in a loop
<p>Lets stay we have the following code: </p>

<pre><code>Var task = Task.Run(() =&gt; RunTest(ct.Token));

Void RunTask(CancellationToken token)
{
If (!token.IsCancellationRequested)
}

 Cmd.CommandText = code;
 Cmd.ExecuteNonQuery();
}
}
</code></pre>

<p>This does now cancel a long running SQL query which is running, how can I immediately kill the task if Cancellation is requested and terminate the long running SQL query? I know about the 'Cancel()' but how can I trigger it based on the cancellationToken?</p>