I hope someone has a good answer to this question.
I have an application that grabs some data and shows a report. The process of comping the report takes about 20 minutes and I want the user to be able to click a Cancel command to stop this.
I want to use the .NET 4.0 Cancellation Token. My main problem is not cancelling the thread that is fetching the data, but once the thread actually completes and updates the dataset with all the informatin. How do I let the application know that the first thread completed? What is the best practice to do this? Keeping in mind that my application needs to remain responsive for the user.
If anyone has some experience with this type of a setup, I would welcome your input.
Thank you.
This example assumes that your LongRunningProcess returns a string (but that can be changed in the delegate definition).
Also - if you are doing this from a UI control (a WinForm for example) - a BackgroundWorker is the way to go. It has built in cancellation and progress notification capabilities - and is extremely straightforward to use. It keeps the UI responsive while delegating the background task.
Open in new window