1
0
mirror of https://bitbucket.org/cjdskunkworks/lynxastrodewcontroller.git synced 2026-05-03 17:28:52 +00:00
Files
lynxastrodewcontroller/LynxAstro.DewController/GarbageCollection.cs
T

58 lines
1.4 KiB
C#

using System;
using System.Threading;
namespace ASCOM.LynxAstro.DewController
{
/// <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()
{
// Pause for a moment to provide a delay to make threads more apparent.
while (ContinueThread())
{
GC.Collect();
Thread.Sleep(m_iInterval);
}
m_EventThreadEnded.Set();
}
protected bool ContinueThread()
{
lock (this)
{
return m_bContinueThread;
}
}
public void StopThread()
{
lock (this)
{
m_bContinueThread = false;
}
}
public void WaitForThreadToStop()
{
m_EventThreadEnded.WaitOne();
m_EventThreadEnded.Reset();
}
}
}