forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRThread.cs
More file actions
101 lines (82 loc) · 2.22 KB
/
Copy pathRThread.cs
File metadata and controls
101 lines (82 loc) · 2.22 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
98
99
100
101
using System;
using System.Threading;
using NLog;
namespace L2dotNET.Managers
{
public class RThread
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public Action PerformAction;
public Action[] PerformActions;
public RThreadType Type;
private Thread _thread;
public object Id;
public int StartWait;
public int Ticks;
public int TickSleep;
public bool Debug = false;
~RThread()
{
if (Debug)
Log.Info($"Thread[{Id}] was erased");
}
public void Start()
{
switch (Type)
{
case RThreadType.General:
_thread = new Thread(DoWorkGeneral);
break;
case RThreadType.GeneralTick:
_thread = new Thread(DoWorkGeneralTick);
break;
case RThreadType.Actions:
_thread = new Thread(DoWorkActions);
break;
}
_thread.Start();
}
private void DoWorkActions()
{
if (StartWait > 0)
Thread.Sleep(StartWait);
for (int a = 0; a < Ticks; a++)
{
if (TickSleep > 0)
Thread.Sleep(TickSleep);
PerformActions[a]();
}
OnEnd();
}
private void DoWorkGeneralTick()
{
if (StartWait > 0)
Thread.Sleep(StartWait);
for (int a = 0; a < Ticks; a++)
{
if (TickSleep > 0)
Thread.Sleep(TickSleep);
PerformAction();
}
OnEnd();
}
private void DoWorkGeneral()
{
if (StartWait > 0)
Thread.Sleep(StartWait);
PerformAction();
OnEnd();
}
public void AbortMe()
{
if (_thread.IsAlive)
_thread.Abort();
_thread = null;
OnEnd();
}
private void OnEnd()
{
ThreadPoolManager.GetInstance().CloseMe(this);
}
}
}