I've got a MySQL connection which is executing a query in a separate thread, represented by a Task.
Through the cancellation token, I am stopping this thread when the user clicks a button.
My problem is that an error is being presented saying the following: Lock wait timeout exceeded; try restarting transaction
This is my code:
cancellationToken = new CancellationTokenSource();
await Task.Run(() =>
{
using (MySqlConnection connection = new MySqlConnection(sourceDatabaseConnectionString))
{
connection.Open();
using (MySqlCommand command = new MySqlCommand(sql, connection))
{
command.CommandTimeout = 0;
command.Parameters.AddWithValue("@month", datePicker.Value.Month);
command.Parameters.AddWithValue("@year", datePicker.Value.Year);
int rows = command.ExecuteNonQuery();
}
}
}
}, cancellationToken.Token);
On button press, I'm calling cancellationToken.Cancel();
When I try to execute the SQL statement again by starting the task, I get the error message shown above. What could be causing it?