Okay,
There seems to be a lot of discussion on here about how terribly awful Thread.Abort() is, and how to work around using Thread.Abort() in your code by adding exit checks in your loop.
This assumes that you control how the work is being partitioned in a way that's granular enough to loop over it.
But how do I do the following:
Launch worker thread to do something while keeping the UI responsive. For all intents and purposes the code for the worker thread looks like this:
public override void Run() { try { _dataTable = ExecuteSingleGinormousSqlQuery(); } finally { // close the connection if it was left open. } }
Have "Cancel" button so that the user can interrupt this if they get bored of waiting.
It doesn't seem like there's any other way around this than with Thread.Abort(). Is that true? Furthermore, in empirical tests, it doesn't even seem like Thread.Abort() actually kills the thread until the call that is making the query, e.g.
new SqlDataAdapter(cmd).Fill( ds );
comes back in the first place, thus significantly negating its utility.
Is there a way around this? Best practices?