Example #1
0
        /// <summary>
        /// DoWorkEventHandler for public method ApproximatePi.
        /// </summary>
        private void ApproximatePiWorkerThreadRoutine(object sender, DoWorkEventArgs e)
        {
            // Call the model layer to calculate the scenarios
            int numberOfScenarios = (int)e.Argument;
            PiScenarioContainer scenarioContainer = model.ApproximatePi(numberOfScenarios);

            e.Result = scenarioContainer;
        }
Example #2
0
 /// <summary>
 /// RunWorkerCompletedEventHandler for public method ApproximatePi.
 /// </summary>
 private void ApproximatePiWorkCompleteRoutine(object sender, RunWorkerCompletedEventArgs e)
 {
     // If an exeception occurred during the worker thread execution, handle it
     if (e.Error != null)
     {
         mainView.ShowErrorMessage(e.Error.Message);
         mainView.Enable();
     }
     else
     {
         // Populate the view
         PiScenarioContainer scenarioContainer = (PiScenarioContainer)e.Result;
         for (int i = 0; i < scenarioContainer.Scenarios.Length; i = i + 1)
         {
             mainView.AddScenarioValue(i + 1, scenarioContainer.Scenarios[i]);
         }
         mainView.PopulatePiValue(scenarioContainer.PiApproximation);
         mainView.Enable();
     }
 }