private void downloadRealtimeDataOperations() { //Step 2: download and load raw data //do 3 different download tasks separately #region ParallelTasks Parallel.Invoke(() => { currentModel.DownloadNextBusGPSData(); }, // close first Action () => { currentModel.DownloadTorontoIncidentData(); }, //close second Action () => { currentModel.DownloadWeatherData(); } //close third Action, //() => {} //close forth Action ); //close parallel.invoke #endregion this.Dispatcher.Invoke(() => { setMenuButtonState(MenuButtonState.Default); SSProgressBar.SetPercent(100, 1); }); GC.Collect(); GC.WaitForPendingFinalizers(); }
private void downloadRealtimeData_Click(object sender, RoutedEventArgs e) { //currentModel.TaskUpdate += c_SSimulatorTaskUpdate;//event listener SSProgressBar.SetPercent(0, 0); //keep button disabled during run setMenuButtonState(MenuButtonState.Operating); updateSettings();//ensure setting is up to date string message = "Confirm that the live data download setting is updated."; string caption = "Confirmation"; MessageBoxButton buttons = MessageBoxButton.OKCancel; MessageBoxImage icon = MessageBoxImage.Question; if (MessageBox.Show(message, caption, buttons, icon) == MessageBoxResult.OK) { //Info on multithreading https://msdn.microsoft.com/en-us/library/mt679047.aspx downloadThread = new Thread(new ThreadStart(downloadRealtimeDataOperations)); downloadThread.Start(); //while (!dataProcessThread.ThreadState.Equals(ThreadState.Stopped)) //{ //} } else { //enable buttons after run setMenuButtonState(MenuButtonState.Default); SSProgressBar.SetPercent(100, 0.2); runLogSS.AppendText("Data Download Aborted.\n"); } }
private void updateProgressStatus(string statusMessage, double progressPercent, double progressDurationInSecs) { this.Dispatcher.Invoke(() => { runStatusSS.AppendText(statusMessage); SSProgressBar.SetPercent(progressPercent, progressDurationInSecs); }); }