using System; using System.Collections.Generic; using System.Text; using ProcessHacker.Native.Api; using ProcessHacker.Native.Objects; using ProcessHacker.Native.Security; namespace ProcessHacker.Native.Threading { /// /// Represents a thread synchronization event. /// public class Event : NativeObject { /// /// Creates an event. /// public Event() : this(null) { } /// /// Creates an event. /// /// /// Whether the event should automatically reset to a non-signaled state /// after all waiters are released. /// /// /// Whether the event should be set to a signaled state initially. /// public Event(bool autoReset, bool initialState) : this(null, autoReset, initialState) { } /// /// Creates or opens an event. /// /// /// The name of the new event, or the name of an existing event to open. /// public Event(string name) : this(name, false, false) { } /// /// Creates an event. /// /// /// The name of the new event. /// /// /// Whether the event should automatically reset to a non-signaled state /// after all waiters are released. /// /// /// Whether the event should be set to a signaled state initially. /// public Event(string name, bool autoReset, bool initialState) { this.Handle = EventHandle.Create( EventAccess.All, name, ObjectFlags.OpenIf, null, autoReset ? EventType.SynchronizationEvent : EventType.NotificationEvent, initialState ); } /// /// Gets whether the event will automatically reset /// after waiters are released. /// public bool AutoReset { get { return this.Handle.GetBasicInformation().EventType == EventType.SynchronizationEvent; } } /// /// Gets whether the event is in the signaled state. /// public bool Signaled { get { return this.Handle.GetBasicInformation().EventState != 0; } } /// /// Attempts to satisfy as many waits as possible and sets /// the event's state to non-signaled. /// public void Pulse() { this.Handle.Pulse(); } /// /// Sets the event's state to non-signaled. /// public void Reset() { this.Handle.Reset(); } /// /// Sets the event's state to signaled. /// public void Set() { this.Handle.Set(); } } }