Browse Source

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

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

21
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<ProgressReportModel> progress = new Progress<ProgressReportModel>();
progress.ProgressChanged += reportProgress;
TreeNode tN = await Task.Run(() => buildResultTree(mainController, progress));
resultViewer.Nodes.Clear();
resultViewer.Nodes.Add(tN);
if (mainController.isStopped)
{
mainController.beginTask();
Progress<ProgressReportModel> progress = new Progress<ProgressReportModel>();
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)

21
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;

Loading…
Cancel
Save