mirror of
https://github.com/SDRSharpR/SDRSharper.git
synced 2026-01-06 00:09:58 +01:00
74 lines
873 B
C#
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;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|