SDRSharper/SDRSharper.Radio/SDRSharp.Radio/SharpEvent.cs
SDRSharpR c07e6e6034 SDRSharper (SDRSharp Remake) Full Source (VS2017)
SDRSharper (SDRSharp Remake) Full Source (VS2017)
2018-03-26 14:02:05 -07:00

74 lines
873 B
C#

using System;
using System.Threading;
namespace SDRSharp.Radio
{
public sealed class SharpEvent
{
private bool _state;
private bool _waiting;
public SharpEvent(bool initialState)
{
this._state = initialState;
}
public SharpEvent()
: this(false)
{
}
~SharpEvent()
{
this.Dispose();
}
public void Dispose()
{
this.Set();
GC.SuppressFinalize(this);
}
public void Set()
{
lock (this)
{
this._state = true;
if (this._waiting)
{
Monitor.Pulse(this);
}
}
}
public void WaitOne()
{
lock (this)
{
if (!this._state)
{
this._waiting = true;
try
{
Monitor.Wait(this);
}
finally
{
this._waiting = false;
}
}
this._state = false;
}
}
public void Reset()
{
lock (this)
{
this._state = false;
}
}
}
}