public void Execute(object parameter) { string chosenPath = parent.FilePathLabelData; string chosenFodlerPath = parent.CountryFolderPathLabelData; if (string.IsNullOrEmpty(chosenPath.Trim())) { return; } parent.FileProcessingLabelData = StringConsts.FileProcessingLabelData_Processing; try { Task.Factory.StartNew(() => { ShareholderAnalyzerLogic ms = new ShareholderAnalyzerLogic(); ms.ProcessFile(chosenPath, chosenFodlerPath); }) .ContinueWith((action) => { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { parent.FileProcessingLabelData = StringConsts.FileProcessingLabelData_Finish; Console.WriteLine(StringConsts.FileProcessingLabelData_Finish); })); }); } catch (Exception) { parent.FileProcessingLabelData = StringConsts.FileProcessingLabelData_ErrorMessage; } }
private void ProcessFilesButton_Click(object sender, EventArgs e) { if (!CanRunProcess()) { MessageBox.Show("Need to specify both files", "Processing cannot be started!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ms = new ShareholderAnalyzerLogic(chosenPath, choosenTermsFilePath); if (string.IsNullOrEmpty(chosenPath.Trim())) { return; } StatusLabelText.Text = "Processing"; ProcessFilesButton.BeginInvoke((MethodInvoker) delegate() { ProcessFilesButton.Enabled = false; }); ChooseFirstFolderButton.BeginInvoke((MethodInvoker) delegate() { ChooseFirstFolderButton.Enabled = false; }); try { new Task(() => { Thread t = new Thread(RunProgram); t.Start(); t.Join(); StatusLabelText.BeginInvoke((MethodInvoker) delegate() { StatusLabelText.Text = "Finish"; }); ProcessFilesButton.BeginInvoke((MethodInvoker) delegate() { ProcessFilesButton.Enabled = true; }); ChooseFirstFolderButton.BeginInvoke((MethodInvoker) delegate() { ChooseFirstFolderButton.Enabled = true; }); Console.WriteLine("Finish"); }).Start(); } catch (Exception) { StatusLabelText.Text = "Something wrong"; } }