forked from golfandsurf/Campah
/
ThreadManager.cs
40 lines (37 loc) · 1.03 KB
/
ThreadManager.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace CampahApp
{
class ThreadManager
{
static List<ThreadStart> Methods = new List<ThreadStart>();
public static void stopThread(ThreadStart method)
{
int i = 0;
for (i = 0; i <= Methods.Count - 1; i++)
{
if (Methods[i].Method.Name == method.Method.Name)
{
Threads[i].Abort();
Threads.RemoveAt(i);
Methods.RemoveAt(i);
}
}
}
static List<Thread> Threads = new List<Thread>();
public static void threadRunner(ThreadStart method)
{
Thread TH = new Thread(method);
TH.IsBackground = true;
TH.Start();
if (TH.IsAlive)
{
Threads.Add(TH);
Methods.Add(method);
}
}
}
}