Lets stay we have the following code:
Var task = Task.Run(() => RunTest(ct.Token));
Void RunTask(CancellationToken token)
{
If (!token.IsCancellationRequested)
}
Cmd.CommandText = code;
Cmd.ExecuteNonQuery();
}
}
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?