private void ProcessTrainFacesButton_Click(object sender, EventArgs e) { if (!TrainFacePrefixTextBox.IsEmpty("Train face prefix,")) { ResetProgress(trainFaceFileCount); var prefix = TrainFacePrefixTextBox.Text; var outputName = "trainDataFace" + trainFaceFileCount + "_records" + ".csv"; ProcessDirAsync(dirTrainFaceBmp, outputName, ImageType.Face, true, prefix, "D5", trainFacesStartIndex, trainFacesEndIndex); } }
private async void ProcessTrainFaceBoth_Click(object sender, EventArgs e) { if (!TrainNotFacePrefixTextBox.IsEmpty("Train not face prefix,") || !TrainFacePrefixTextBox.IsEmpty("Train face prefix,")) { var totalFiles = trainFaceFileCount + trainNotFaceFileCount; ResetProgress(totalFiles); var prefix = TrainFacePrefixTextBox.Text; var prefix2 = TrainNotFacePrefixTextBox.Text; Form1.Instance.ClearOutput(); Form1.Instance.SetCurrentStatus("Processing..."); var cancelTokenSource = new CancellationTokenSource(); cancelTokenSources.Add(cancelTokenSource); var token = cancelTokenSource.Token; Directory.CreateDirectory(dirEvaluationDataSet); string outputFile = dirEvaluationDataSet + "trainDataBoth_" + totalFiles + "_records" + ".csv"; using (File.Create(outputFile)) { }; try { Task taskTrainFace = Task.Factory.StartNew(() => Work(dirTrainFaceBmp, outputFile, ImageType.Face, true, prefix, "D5", trainFacesStartIndex, trainFacesEndIndex), token); await Task.WhenAll(taskTrainFace); Task taskTrainNotFace = Task.Factory.StartNew(() => Work(dirTrainNotFaceBmp, outputFile, ImageType.NotFace, true, prefix2, "D5", trainNonFacesStartIndex, trainNonFacesEndIndex), token); await Task.WhenAll(taskTrainNotFace); Form1.Instance.SetCurrentStatus("Finished!"); } catch (OperationCanceledException) { Form1.Instance.SetCurrentStatus("Stopped!"); } finally { StopButton.Enabled = false; SetControlsEnabledState(true); cancelTokenSources.Remove(cancelTokenSource); } } }