private void Worker_DoWork(object sender, DoWorkEventArgs e) { Debug.WriteLine("Worker started"); worker.ReportProgress(0); // extract all data from worker input BackgroundSimulationInput input = (BackgroundSimulationInput)e.Argument; double timeHorizon = input.timeHorizon; double timeStep = input.timeStep; IterativeSimulator simulator = input.iterativeSimulator; int iterations = (int)Math.Floor(timeHorizon / timeStep) + 1; var executionTime = ExecTime.Run(() => { // first iteration - simulation initialization simulator.PrepareSimulation(timeStep); progressCounter.Initialize(iterations); progressCounter.NextIteration(); // perform calculations for (int i = 1; i < iterations; i++) { if (worker.CancellationPending) { e.Cancel = true; break; } simulator.NextIteration(); progressCounter.NextIteration(); } }); // return result BackgroundSimulationOutput output = new BackgroundSimulationOutput() { totalIterations = iterations, timeStep = timeStep, executionTime = executionTime, data = simulator.GetData() }; e.Result = output; }
public MainForm() { InitializeComponent(); MinimumSize = Size; MainForm_Resize(null, null); UpdateSimulationState(false); InitComboboxes(); backgroundSimulation = new BackgroundSimulation(); backgroundSimulation.OnCancel += Simulator_OnCancel; backgroundSimulation.OnException += Simulator_OnException; backgroundSimulation.OnFinish += Simulator_OnFinish; backgroundSimulation.OnProgress += Simulator_OnProgress; iterativeSimulator = new IterativeSimulator(); chart = new ControlChart(chart1, 0); }