/// <summary> /// Sleep the current thread for a specified number of milliseconds. /// </summary> /// <param name="delay_ms">The delay in milliseconds.</param> /// <returns>True if the thread was alerted before the delay expired.</returns> public static bool SleepMs(long delay_ms) { return(Sleep(false, NtWaitTimeout.FromMilliseconds(delay_ms))); }
internal static LargeInteger ToLargeInteger(this NtWaitTimeout timeout) { return(timeout?.Timeout); }
/// <summary> /// Sleep the current thread /// </summary> /// <param name="alertable">Set if the thread should be alertable</param> /// <param name="delay">The delay, negative values indicate relative times.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>STATUS_ALERTED if the thread was alerted, other success or error code.</returns> public static NtStatus Sleep(bool alertable, NtWaitTimeout delay, bool throw_on_error) { return(NtSystemCalls.NtDelayExecution(alertable, delay?.Timeout).ToNtException(throw_on_error)); }
/// <summary> /// Sleep the current thread /// </summary> /// <param name="alertable">Set if the thread should be alertable</param> /// <param name="delay">The delay, negative values indicate relative times.</param> /// <returns>True if the thread was alerted before the delay expired.</returns> public static bool Sleep(bool alertable, NtWaitTimeout delay) { return(Sleep(alertable, delay, true) == NtStatus.STATUS_ALERTED); }
/// <summary> /// Set the time limit for a job. /// </summary> /// <param name="job_time_limit">The time limit for a job.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The NT status code.</returns> public NtStatus SetJobTimeLimit(NtWaitTimeout job_time_limit, bool throw_on_error) { return(SetJobMemoryLimit(Math.Abs(job_time_limit?.Timeout?.QuadPart ?? 0), throw_on_error)); }
/// <summary> /// Set the time limit for a job. /// </summary> /// <param name="job_time_limit">The time limit for a job.</param> public void SetJobTimeLimit(NtWaitTimeout job_time_limit) { SetJobTimeLimit(job_time_limit, true); }
/// <summary> /// Set the time limit for a process. /// </summary> /// <param name="process_time_limit">The time limit for a process.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The NT status code.</returns> public NtStatus SetProcessTimeLimit(NtWaitTimeout process_time_limit, bool throw_on_error) { return(SetProcessTimeLimit(Math.Abs(process_time_limit?.Timeout?.QuadPart ?? 0), throw_on_error)); }
/// <summary> /// Remove multiple queued status from the queue. /// </summary> /// <param name="max_count">Maximum number of status to remove.</param> /// <param name="timeout">An optional timeout.</param> /// <param name="alertable">Indicate whether the wait is alertable.</param> /// <returns>Array of completion results. Length can be <= max_count. If timeout then returns an empty array.</returns> public FileIoCompletionResult[] Remove(int max_count, NtWaitTimeout timeout, bool alertable) { return(Remove(max_count, timeout, alertable, false).GetResultOrDefault(new FileIoCompletionResult[0])); }
/// <summary> /// Wait on a single object to become signalled /// </summary> /// <param name="obj">The object to wait on</param> /// <param name="alertable">Whether the thread should be alerable</param> /// <param name="timeout">The timeout to wait for</param> /// <returns>The success status of the wait, such as STATUS_SUCCESS or STATUS_TIMEOUT</returns> public static NtStatus Wait(NtObject obj, bool alertable, NtWaitTimeout timeout) { return(NtSystemCalls.NtWaitForSingleObject(obj.Handle, alertable, timeout.ToLargeInteger()).ToNtException()); }
/// <summary> /// Wait on multiple objects to become signalled /// </summary> /// <param name="objs">The objects to wait on</param> /// <param name="alertable">Whether the thread should be alerable</param> /// <param name="wait_all">True to wait for all objects to be signalled</param> /// <param name="timeout">The timeout to wait for</param> /// <returns>The success status of the wait, such as STATUS_WAIT_OBJECT_0 or STATUS_TIMEOUT</returns> public static NtStatus Wait(IEnumerable <NtObject> objs, bool alertable, bool wait_all, NtWaitTimeout timeout) { IntPtr[] handles = objs.Select(o => o.Handle.DangerousGetHandle()).ToArray(); return(NtSystemCalls.NtWaitForMultipleObjects(handles.Length, handles, wait_all ? WaitType.WaitAll : WaitType.WaitAny, alertable, timeout.ToLargeInteger()).ToNtException()); }
/// <summary> /// Wait on the object to become signalled /// </summary> /// <param name="alertable">True to make the wait alertable</param> /// <param name="timeout_sec">The time out in seconds</param> /// <returns>The success status of the wait, such as STATUS_SUCCESS or STATUS_TIMEOUT</returns> /// <exception cref="NtException">Thrown on error</exception> public NtStatus Wait(bool alertable, int timeout_sec) { return(Wait(alertable, NtWaitTimeout.FromSeconds(timeout_sec))); }
/// <summary> /// Wait on the object to become signalled /// </summary> /// <param name="timeout">The time out</param> /// <returns>The success status of the wait, such as STATUS_SUCCESS or STATUS_TIMEOUT</returns> /// <exception cref="NtException">Thrown on error</exception> public NtStatus Wait(NtWaitTimeout timeout) { return(Wait(false, timeout)); }
/// <summary> /// Wait on the object to become signalled /// </summary> /// <param name="alertable">True to make the wait alertable</param> /// <param name="timeout">The time out</param> /// <returns>The success status of the wait, such as STATUS_SUCCESS or STATUS_TIMEOUT</returns> /// <exception cref="NtException">Thrown on error</exception> public NtStatus Wait(bool alertable, NtWaitTimeout timeout) { return(NtWait.Wait(this, alertable, timeout)); }
/// <summary> /// Wait on a single object to become signalled /// </summary> /// <param name="obj">The object to wait on</param> /// <param name="alertable">Whether the thread should be alerable</param> /// <param name="timeout">The timeout to wait for</param> /// <returns>The success status of the wait, such as STATUS_WAIT_OBJECT_0 or STATUS_TIMEOUT</returns> public static NtStatus Wait(NtObject obj, bool alertable, NtWaitTimeout timeout) { return NtSystemCalls.NtWaitForSingleObject(obj.Handle, alertable, timeout.Timeout).ToNtException(); }
/// <summary> /// Set the time limit for a process. /// </summary> /// <param name="process_time_limit">The time limit for a process.</param> public void SetProcessTimeLimit(NtWaitTimeout process_time_limit) { SetProcessTimeLimit(process_time_limit, true); }
/// <summary> /// Wait on multiple objects to become signalled /// </summary> /// <param name="objs">The objects to wait on</param> /// <param name="alertable">Whether the thread should be alerable</param> /// <param name="wait_all">True to wait for all objects to be signalled</param> /// <param name="timeout">The timeout to wait for</param> /// <returns>The success status of the wait, such as STATUS_WAIT_OBJECT_0 or STATUS_TIMEOUT</returns> public static NtStatus Wait(IEnumerable<NtObject> objs, bool alertable, bool wait_all, NtWaitTimeout timeout) { IntPtr[] handles = objs.Select(o => o.Handle.DangerousGetHandle()).ToArray(); return NtSystemCalls.NtWaitForMultipleObjects(handles.Length, handles, wait_all ? WaitType.WaitAll : WaitType.WaitAny, alertable, timeout.Timeout).ToNtException(); }
/// <summary> /// Remove a queued status from the queue. /// </summary> /// <param name="timeout">An optional timeout.</param> /// <returns>The completion result.</returns> /// <exception cref="NtException">Thrown on error or timeout.</exception> public FileIoCompletionResult Remove(NtWaitTimeout timeout) { return(Remove(timeout, true).Result); }