forked from jasonweiyi/XAPI2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGarbageCollection.cs
More file actions
63 lines (56 loc) · 1.31 KB
/
Copy pathGarbageCollection.cs
File metadata and controls
63 lines (56 loc) · 1.31 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
using System;
using System.Threading;
namespace XAPI.COM
{
/// <summary>
/// Summary description for GarbageCollection.
/// </summary>
class GarbageCollection
{
protected bool m_bContinueThread;
protected bool m_GCWatchStopped;
protected int m_iInterval;
protected ManualResetEvent m_EventThreadEnded;
public GarbageCollection(int iInterval)
{
m_bContinueThread = true;
m_GCWatchStopped = false;
m_iInterval = iInterval;
m_EventThreadEnded = new ManualResetEvent(false);
}
public void GCWatch()
{
Console.WriteLine("GarbageCollection.GCWatch() is now running on another thread.");
// Pause for a moment to provide a delay to make threads more apparent.
while (ContinueThread())
{
GC.Collect();
Thread.Sleep(m_iInterval);
}
Console.WriteLine("Goind to call m_EventThreadEnded.Set().");
m_EventThreadEnded.Set();
}
protected bool ContinueThread()
{
lock(this)
{
return m_bContinueThread;
}
}
public void StopThread()
{
lock(this)
{
Console.WriteLine("StopThread().");
m_bContinueThread = false;
}
}
public void WaitForThreadToStop()
{
Console.WriteLine("WaitForThreadToStop().");
m_EventThreadEnded.WaitOne();
m_EventThreadEnded.Reset();
Console.WriteLine("WaitForThreadToStop() exiting.");
}
}
}