-
-
Notifications
You must be signed in to change notification settings - Fork 334
/
LinearTaskExecutor.cs
45 lines (40 loc) · 1.27 KB
/
LinearTaskExecutor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
namespace GeneticSharp
{
/// <summary>
/// An ITaskExecutor's implementation that executes the tasks in a linear fashion.
/// </summary>
public class LinearTaskExecutor : TaskExecutorBase
{
#region implemented abstract members of TaskExecutorBase
/// <summary>
/// Starts the tasks execution.
/// </summary>
/// <returns>If has reach the timeout false, otherwise true.</returns>
public override bool Start()
{
var startTime = DateTime.Now;
base.Start();
// For each Tasks passed to excutor,
// run it one in linear way.
for (int i = 0; i < Tasks.Count; i++)
{
// Check if a stop was requested.
if (StopRequested)
{
return true;
}
Tasks[i]();
// If take more time expected on Timeout property,
// tehn stop thre running.
if ((DateTime.Now - startTime) > Timeout)
{
return false;
}
}
IsRunning = false;
return true;
}
#endregion
}
}