forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadPoolManager.cs
More file actions
97 lines (79 loc) · 2.58 KB
/
ThreadPoolManager.cs
File metadata and controls
97 lines (79 loc) · 2.58 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using log4net;
namespace L2dotNET.managers
{
public class ThreadPoolManager
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ThreadPoolManager));
private static readonly ThreadPoolManager Instance = new ThreadPoolManager();
public static ThreadPoolManager GetInstance()
{
return Instance;
}
public Dictionary<object, RThread> Threads = new Dictionary<object, RThread>();
public void ExecuteGeneral(Action action, int wait = 0, object id = null)
{
RThread thread = new RThread
{
Type = RThreadType.General,
Id = id,
StartWait = wait,
PerformAction = action
};
if (id != null)
Threads.Add(thread.Id, thread);
thread.Start();
Log.Info($"threads {Threads.Count}");
}
public void ExecuteGeneralTicks(Action action, int ticks, int tickWait = 1000, int wait = 0, object id = null)
{
RThread thread = new RThread
{
Type = RThreadType.GeneralTick,
Id = id,
StartWait = wait,
PerformAction = action,
Ticks = ticks,
TickSleep = tickWait
};
if (id != null)
Threads.Add(thread.Id, thread);
thread.Start();
}
public void ExecuteActions(Action[] actions, int tickWait = 1000, int wait = 0, object id = null)
{
RThread thread = new RThread
{
Type = RThreadType.Actions,
Id = id,
StartWait = wait,
PerformActions = actions,
Ticks = actions.Length,
TickSleep = tickWait
};
if (id != null)
Threads.Add(thread.Id, thread);
thread.Start();
}
public void ExecuteActionParams(int wait, int tickWait, params Action[] at)
{
ExecuteActions(at, tickWait, wait);
}
public void StopThread(object id)
{
if (Threads.ContainsKey(id))
Threads[id].AbortMe();
}
public void CloseMe(RThread thread)
{
if (thread.Id != null)
{
lock (Threads)
Threads.Remove(thread.Id);
}
GC.Collect(0, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
}
}
}