-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskManager.cs
46 lines (39 loc) · 1.19 KB
/
TaskManager.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
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WheelOfSteamGames
{
class TaskManager
{
public delegate void OnTaskCompleted(IAsyncResult task);
private static List<Task> CurrentTasks = new List<Task>();
public struct Task
{
public IAsyncResult Result;
public string Name;
public OnTaskCompleted onDoneDel;
public Task(string name, IAsyncResult result, OnTaskCompleted del)
{
Name = name;
Result = result;
onDoneDel = del;
}
}
public static void AddTask(IAsyncResult result, OnTaskCompleted del, string name = "none")
{
Task task = new Task(name, result, del);
CurrentTasks.Add(task);
}
public static void PollTasks()
{
for (int i = 0; i < CurrentTasks.Count; i++)
{
Task task = CurrentTasks[i];
if (!task.Result.IsCompleted) continue;
task.onDoneDel.Invoke(task.Result);
if (CurrentTasks.Remove(task)) i--;
}
}
}
}