diff --git a/fileFinder/MainForm.cs b/fileFinder/MainForm.cs index e40ac46..016310c 100644 --- a/fileFinder/MainForm.cs +++ b/fileFinder/MainForm.cs @@ -85,7 +85,6 @@ namespace fileFinder { MessageBox.Show(ex.Message, "Ошибка поиска внутри файла!"); } - _report.progress = counter; _report.currentFileUrl = item; report.Report(_report); @@ -128,11 +127,21 @@ namespace fileFinder private async void handleSearchBtn_Click(object sender, EventArgs e) { - Progress progress = new Progress(); - progress.ProgressChanged += reportProgress; - TreeNode tN = await Task.Run(() => buildResultTree(mainController, progress)); - resultViewer.Nodes.Clear(); - resultViewer.Nodes.Add(tN); + if (mainController.isStopped) + { + mainController.beginTask(); + Progress progress = new Progress(); + progress.ProgressChanged += reportProgress; + TreeNode tN = await Task.Run(() => buildResultTree(mainController, progress)); + resultViewer.Nodes.Clear(); + resultViewer.Nodes.Add(tN); + } else if (mainController.isPaused) + { + mainController.resumeTask(); + } else + { + mainController.pauseTask(); + } } public async Task fillChildNode (TreeNode node, String item) diff --git a/fileFinder/TaskController.cs b/fileFinder/TaskController.cs index 09588c6..04b6d01 100644 --- a/fileFinder/TaskController.cs +++ b/fileFinder/TaskController.cs @@ -9,17 +9,24 @@ namespace fileFinder class TaskController { public bool isPaused { get; private set; } - public bool isFinished { get; private set; } + public bool isStopped { get; private set; } public TaskController () { isPaused = false; - isFinished = false; + isStopped = true; } - public bool pauseTask() + public bool beginTask () { - if (!isPaused && !isFinished) + isPaused = false; + isStopped = false; + return true; + } + + public bool pauseTask () + { + if (!isPaused && !isStopped) { isPaused = true; return true; @@ -29,7 +36,7 @@ namespace fileFinder public bool resumeTask () { - if (isPaused && !isFinished) + if (isPaused && !isStopped) { isPaused = false; return true; @@ -39,9 +46,9 @@ namespace fileFinder public bool stopTask () { - if (!isFinished) + if (!isStopped) { - isFinished = true; + isStopped = true; return true; } else return false;