class · System.Threading

ManualResetEvent

public class ManualResetEvent

An event that stays set until Reset: WaitOne returns at once while it is set.

Tipo
class
Espacio de nombres
System.Threading
Ensamblado
System.Core
Acceso
public
Archivo fuente
Threading.ant

Herencia

Clases base
Any ManualResetEvent
Tipos derivados
AutoResetEvent

Constructores

new(bool initialState)
#

Propiedades

bool IsSet { get; }
#

read-only

Métodos

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).

Campos

Mutex mutex
#

inherited

Condition changed
#

inherited

bool set
#

inherited

Miembros heredados (5)

Código fuente

ManualResetEvent en Antril, descompilado a partir de su 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