I run a series of time consuming operations on a background worker thread. At various stages I update a (windows form) progress bar by invoking a delegate. However, one of the more time operations occurs on a single line of code.
Is it possible to :
a) Update the UI while that single line of code is being executed, or at least display an animated icon that shows the user that work is being done.
b) Let the user cancel the background worker thread while that single line of code is being executed
Unfortunately, probably not. The background worker thread needs to call ReportProgress to update the UI thread, and it needs to watch the CancellationPending to know whether it should stop or not. So, if your worker thread is running along-running operation in a single line, there’s no way to make this work.
Perhaps, I’ve misunderstood, so here’s code that simulates what I’m getting at: