Hello,
I am writing a program at the moment which is able to solve a certain set of differential equations for subsequent time steps.
I would like to implement it in such a way that one can press "start" and it will start the calculation timestep by timestep until it reaches some max number of steps, however, I also want to implement a button called "stop" so it can stop the calculations at a time decided by the user.
At the moment I don't know how to do that, because during the calculations the window just doesn't react and if I try to click something it crashes (so i guess it is stuck in calculations).
Is there a way to overcome this somehow?
Cheers,
Phil
Loading
VulpesPosted Dec 10, 2011, 1:28 PM
You can also cancel it by calling the CancelAsync method from your stop button's Click eventhandler.
Check out the MSDN docs which have plenty of examples:
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
I'd also check the articles on this site:
http://www.c-sharpcorner.com/Search/?sKeywords=backgroundworker
Also here's an example for WPF specifically:
http://elegantcode.com/2009/07/03/wpf-multithreading-using-the-backgroundworker-and-reporting-the-progress-to-the-ui/