class · System.Threading
ManualResetEvent
public class ManualResetEvent
An event that stays set until Reset: WaitOne returns at once while it is set.
- Kind
- class
- Namespace
- System.Threading
- Assembly
- System.Core
- Access
- public
- Source file
Threading.ant
Inheritance
- Base classes
-
AnyManualResetEvent - Derived types
-
AutoResetEvent
Constructors
Properties
Methods
Set()
#
Reset()
#
virtual WaitOne()
#
Waits at most milliseconds: whether it was set.
Dispose()
#
Frees what it holds (it must not be used after).
Fields
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
ManualResetEvent as Antril, decompiled from its Larva HIR.
// System.Threading.ManualResetEvent — System.Core (decompiled from Larva HIR)
import System;
into namespace System.Threading
{
/// An event that stays set until Reset: WaitOne returns at once while it is set.
public class ManualResetEvent
{
inherited:
Mutex mutex;
Condition changed;
bool set;
public:
new(bool initialState)
{
mutex = new Mutex();
changed = new Condition();
set = initialState;
}
Set()
{
mutex.Lock();
set = true;
mutex.Unlock();
changed.Broadcast();
}
Reset()
{
mutex.Lock();
set = false;
mutex.Unlock();
}
virtual WaitOne()
{
mutex.Lock();
loop (!set)
changed.Wait(mutex);
mutex.Unlock();
}
/// Waits at most `milliseconds`: whether it was set.
virtual WaitOne(i32 milliseconds) : bool
{
i64 until = Environment.TickCount64 + (i64)milliseconds;
mutex.Lock();
loop (!set)
{
i64 left = until - Environment.TickCount64;
if (left <= 0)
break;
changed.Wait(mutex, (i32)left);
}
bool result = set;
mutex.Unlock();
return result;
}
/// Frees what it holds (it must not be used after).
Dispose()
{
mutex.Dispose();
changed.Dispose();
}
bool IsSet
{
get => set;
}
}
}