Browse Source

Теперь кнопка Start/Pause может приостановить поток и запустить обратно. Добавлен resumeTask в TaskController для работы кнопки.

release
Никита 6 years ago
parent
commit
116d7267cd
  1. 11
      fileFinder/MainForm.cs
  2. 21
      fileFinder/TaskController.cs

11
fileFinder/MainForm.cs

@ -85,7 +85,6 @@ namespace fileFinder
{ {
MessageBox.Show(ex.Message, "Ошибка поиска внутри файла!"); MessageBox.Show(ex.Message, "Ошибка поиска внутри файла!");
} }
_report.progress = counter; _report.progress = counter;
_report.currentFileUrl = item; _report.currentFileUrl = item;
report.Report(_report); report.Report(_report);
@ -128,11 +127,21 @@ namespace fileFinder
private async void handleSearchBtn_Click(object sender, EventArgs e) private async void handleSearchBtn_Click(object sender, EventArgs e)
{ {
if (mainController.isStopped)
{
mainController.beginTask();
Progress<ProgressReportModel> progress = new Progress<ProgressReportModel>(); Progress<ProgressReportModel> progress = new Progress<ProgressReportModel>();
progress.ProgressChanged += reportProgress; progress.ProgressChanged += reportProgress;
TreeNode tN = await Task.Run(() => buildResultTree(mainController, progress)); TreeNode tN = await Task.Run(() => buildResultTree(mainController, progress));
resultViewer.Nodes.Clear(); resultViewer.Nodes.Clear();
resultViewer.Nodes.Add(tN); resultViewer.Nodes.Add(tN);
} else if (mainController.isPaused)
{
mainController.resumeTask();
} else
{
mainController.pauseTask();
}
} }
public async Task fillChildNode (TreeNode node, String item) public async Task fillChildNode (TreeNode node, String item)

21
fileFinder/TaskController.cs

@ -9,17 +9,24 @@ namespace fileFinder
class TaskController class TaskController
{ {
public bool isPaused { get; private set; } public bool isPaused { get; private set; }
public bool isFinished { get; private set; } public bool isStopped { get; private set; }
public TaskController () public TaskController ()
{ {
isPaused = false; 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; isPaused = true;
return true; return true;
@ -29,7 +36,7 @@ namespace fileFinder
public bool resumeTask () public bool resumeTask ()
{ {
if (isPaused && !isFinished) if (isPaused && !isStopped)
{ {
isPaused = false; isPaused = false;
return true; return true;
@ -39,9 +46,9 @@ namespace fileFinder
public bool stopTask () public bool stopTask ()
{ {
if (!isFinished) if (!isStopped)
{ {
isFinished = true; isStopped = true;
return true; return true;
} else } else
return false; return false;

Loading…
Cancel
Save