Hi,
I have a hangfire task that calls with ado.net a stored procedure(SqlCommand.ExecuteNonQuery… ).
This can run for several minutes.
Is there a way to cancel/abort the hangfire job or kill the thread while the c# code is waiting for the stored procedure to finish? If the thread could be killed, the connection would be broken and the sql execution will be stopped.
When using cancellationTokens i understand that i can only stop the task before or after the SqlCommand.ExecuteNonQuery command or am i missing something?.
You can use cancellationToken:
- by Openning the SqlConnection with OpenAsync
- implementing a cancel event on the Command like this:
https://stackoverflow.com/questions/24738417/canceling-sql-server-query-with-cancellationtoken