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
Any ManualResetEvent
Derived types
AutoResetEvent

Constructors

new(bool initialState)
#

Properties

bool IsSet { get; }
#

read-only

Methods

Set()
#
Reset()
#
virtual WaitOne()
#

virtual

virtual WaitOne(i32 milliseconds) : bool
#

virtual

Waits at most milliseconds: whether it was set.

Dispose()
#

Frees what it holds (it must not be used after).

Fields

Mutex mutex
#

inherited

Condition changed
#

inherited

bool set
#

inherited

Inherited members (5)

Source

ManualResetEvent as Antril, decompiled from its Larva HIR.

System.Threading.ManualResetEvent.ant
// 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;
			}
	}
}
Esc