public static UInt64 Thread(SafeWaitHandle threadHandle) { UInt64 cycleTime; if (!QueryThreadCycleTime(threadHandle, out cycleTime)) throw new Win32Exception(); return cycleTime; }
public CanlibWaitHandle(object we) { uint theHandle = (uint) we; IntPtr pointer = new IntPtr((long) theHandle); SafeWaitHandle swHandle = new SafeWaitHandle(pointer, true); base.SafeWaitHandle = swHandle; }
public static UInt64 Process(SafeWaitHandle processHandle) { UInt64 cycleTime; if (!QueryProcessCycleTime(processHandle, out cycleTime)) throw new Win32Exception(); return cycleTime; }
public static extern bool SetWaitableTimer( SafeWaitHandle hTimer, [In] ref long pDueTime, int lPeriod, IntPtr pfnCompletionRoutine, IntPtr lpArgToCompletionRoutine, bool fResume);
public static extern int RegNotifyChangeKeyValue( UIntPtr hKey, bool bWatchSubtree, uint dwNotifyFilter, SafeWaitHandle hEvent, bool fAsynchronous );
public Semaphore(int initialCount, int maximumCount, string name) { if (initialCount < 0) { throw new ArgumentOutOfRangeException("initialCount", SR.ArgumentOutOfRange_NeedNonNegNumRequired); } if (maximumCount < 1) { throw new ArgumentOutOfRangeException("maximumCount", SR.ArgumentOutOfRange_NeedPosNum); } if (initialCount > maximumCount) { throw new ArgumentException(SR.Argument_SemaphoreInitialMaximum); } if (null != name && MAX_PATH < name.Length) { throw new ArgumentException(SR.Argument_WaitHandleNameTooLong); } SafeWaitHandle myHandle = new SafeWaitHandle(Interop.mincore.CreateSemaphoreEx(IntPtr.Zero, initialCount, maximumCount, name, 0, (uint)(Interop.Constants.SemaphoreModifyState | Interop.Constants.Synchronize)), true); if (myHandle.IsInvalid) { int errorCode = (int)Interop.mincore.GetLastError(); if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); throw ExceptionFromCreationError(errorCode, name); } SafeWaitHandle = myHandle; }
/// <summary> /// Initializes a new instance of the CycleTime class. /// </summary> /// <param name="trackingThreadTime"> /// True if you want to track the current thread time. False for the /// process as a whole. /// </param> /// <param name="handle"> /// The handle to the process for observing. /// </param> private CycleTime(Boolean trackingThreadTime, SafeWaitHandle handle) { this.trackingThreadTime = trackingThreadTime; this.handle = handle; this.startCycleTime = this.trackingThreadTime ? Thread() : Process(this.handle); }
public SoundCaptureBase(SoundCaptureDevice device) { this.device = device; positionEvent = new AutoResetEvent(false); positionEventHandle = positionEvent.SafeWaitHandle; terminated = new ManualResetEvent(true); }
/// <summary> /// Retrieves the sum of the cycle time of all threads of the specified /// process. /// </summary> public static ulong Process(SafeWaitHandle processHandle) { ulong cycleTime; if (!QueryProcessCycleTime(processHandle, out cycleTime)) { throw new Win32Exception(); } return cycleTime; }
/// <summary> /// Retrieves the cycle time for the specified thread. /// </summary> public static ulong Thread(SafeWaitHandle threadHandle) { ulong cycleTime; if (!QueryThreadCycleTime(threadHandle, out cycleTime)) { throw new Win32Exception(); } return cycleTime; }
public void CancelWakeUp() { if (handle != null && !handle.IsClosed) { CancelWaitableTimer(handle); handle.Close(); } handle = null; }
public static void SetSafeWaitHandle(this WaitHandle waitHandle, SafeWaitHandle value) { if (waitHandle == null) { throw new ArgumentNullException(nameof(waitHandle)); } waitHandle.SafeWaitHandle = value; }
public static bool ResetEvent (SafeWaitHandle handle) { bool release = false; try { handle.DangerousAddRef (ref release); return ResetEvent_internal (handle.DangerousGetHandle ()); } finally { if (release) handle.DangerousRelease (); } }
public WaitHandle AbsoluteTimer(DateTimeOffset expireAt) { var handle = CreateWaitableTimer(IntPtr.Zero, true, null); var dueTime = expireAt.ToUniversalTime().ToFileTime(); SetWaitableTimer(handle, ref dueTime, 0, IntPtr.Zero, IntPtr.Zero, false); var safeHandle = new SafeWaitHandle(handle, true); return new TimerWaitHandle(safeHandle); }
public ProcessInfo( Process ps, ProcessInformation psi) { if (null == ps) { throw new ArgumentNullException("ps"); } this.ps = ps; this.mainThreadHandle = new SafeWaitHandle( psi.hThread, true); }
internal ByteRangeDownloader(Uri requestedUri, string tempFileName, SafeWaitHandle eventHandle) : this(requestedUri, eventHandle) { if (tempFileName == null) { throw new ArgumentNullException("tempFileName"); } if (tempFileName.Length <= 0) { throw new ArgumentException(SR.Get(SRID.InvalidTempFileName), "tempFileName"); } _tempFileStream = File.Open(tempFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); }
public bool CreatePipeandEvent(string strPiPeName, string strEventName) { try { m_strPiPeName = strPiPeName; m_strEventName = strEventName; pipeStream = new NamedPipeServerStream(strPiPeName); m_handle = CoreEvent.CreateEvent(default(IntPtr), false, false, strEventName); strNO = strNO + "1"; return(true); } catch (Exception es) { return(false); } }
public EventWaitHandle(bool initialState, EventResetMode mode, string name) { if(null != name && System.IO.Path.MAX_PATH < name.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name)); } Contract.EndContractBlock(); SafeWaitHandle _handle = null; #if MONO int errorCode; #endif switch(mode) { case EventResetMode.ManualReset: #if MONO _handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (true, initialState, name, out errorCode), true); #else _handle = Win32Native.CreateEvent(null, true, initialState, name); #endif break; case EventResetMode.AutoReset: #if MONO _handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (false, initialState, name, out errorCode), true); #else _handle = Win32Native.CreateEvent(null, false, initialState, name); #endif break; default: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag",name)); }; if (_handle.IsInvalid) { #if !MONO int errorCode = Marshal.GetLastWin32Error(); #endif _handle.SetHandleAsInvalid(); if(null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle",name)); __Error.WinIOError(errorCode, name); } SetHandleInternal(_handle); }
public Semaphore(int initialCount, int maximumCount, string name) { if (initialCount < 0) { throw new ArgumentOutOfRangeException("initialCount", SR.GetString(SR.ArgumentOutOfRange_NeedNonNegNumRequired)); } if (maximumCount < 1) { throw new ArgumentOutOfRangeException("maximumCount", SR.GetString(SR.ArgumentOutOfRange_NeedPosNum)); } if (initialCount > maximumCount) { throw new ArgumentException(SR.GetString(SR.Argument_SemaphoreInitialMaximum)); } if(null != name && MAX_PATH < name.Length) { throw new ArgumentException(SR.GetString(SR.Argument_WaitHandleNameTooLong)); } #if MONO int errorCode; var myHandle = new SafeWaitHandle (CreateSemaphore_internal (initialCount, maximumCount, name, out errorCode), true); #else SafeWaitHandle myHandle = SafeNativeMethods.CreateSemaphore(null, initialCount, maximumCount, name); #endif if (myHandle.IsInvalid) { #if !MONO int errorCode = Marshal.GetLastWin32Error(); #endif if(null != name && 0 != name.Length && NativeMethods.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(SR.GetString(SR.WaitHandleCannotBeOpenedException_InvalidHandle,name)); #if MONO InternalResources.WinIOError(errorCode, ""); #else InternalResources.WinIOError(); #endif } this.SafeWaitHandle = myHandle; }
public EventWaitHandle(bool initialState, EventResetMode mode, string name) { if (null != name) { if (((int)Interop.Constants.MaxPath) < name.Length) { throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name)); } } Contract.EndContractBlock(); uint eventFlags = initialState ? (uint)Interop.Constants.CreateEventInitialSet : 0; IntPtr unsafeHandle; switch (mode) { case EventResetMode.ManualReset: eventFlags |= (uint)Interop.Constants.CreateEventManualReset; break; case EventResetMode.AutoReset: break; default: throw new ArgumentException(SR.Format(SR.Argument_InvalidFlag, name)); }; unsafeHandle = Interop.mincore.CreateEventEx(IntPtr.Zero, name, eventFlags, (uint)Interop.Constants.EventAllAccess); int errorCode = (int)Interop.mincore.GetLastError(); SafeWaitHandle _handle = new SafeWaitHandle(unsafeHandle, true); if (_handle.IsInvalid) { _handle.SetHandleAsInvalid(); if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); throw ExceptionFromCreationError(errorCode, name); } SafeWaitHandle = _handle; }
internal void Persist(SafeWaitHandle handle) { base.WriteLock(); try { AccessControlSections accessControlSectionsFromChanges = this.GetAccessControlSectionsFromChanges(); if (accessControlSectionsFromChanges != AccessControlSections.None) { bool flag; bool flag2; base.Persist(handle, accessControlSectionsFromChanges); base.AccessRulesModified = flag = false; base.AuditRulesModified = flag2 = flag; base.OwnerModified = base.GroupModified = flag2; } } finally { base.WriteUnlock(); } }
private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { long waketime = (long)e.Argument; using (handle = CreateWaitableTimer(IntPtr.Zero, true, this.GetType().Assembly.GetName().Name.ToString() + "Timer")) { if (SetWaitableTimer(handle, ref waketime, 0, IntPtr.Zero, IntPtr.Zero, true)) { using (wh = new EventWaitHandle(false, EventResetMode.AutoReset)) { wh.SafeWaitHandle = handle; wh.WaitOne(); } } else { throw new Win32Exception(Marshal.GetLastWin32Error()); } } wh = null; }
public static bool DuplicateHandle(HandleRef hSourceProcessHandle, SafeHandle hSourceHandle, HandleRef hTargetProcess, out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions) { bool release = false; try { hSourceHandle.DangerousAddRef (ref release); MonoIOError error; IntPtr nakedTargetHandle; bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.DangerousGetHandle (), hTargetProcess.Handle, out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error); if (error != MonoIOError.ERROR_SUCCESS) throw MonoIO.GetException (error); targetHandle = new SafeWaitHandle (nakedTargetHandle, true); return ret; } finally { if (release) hSourceHandle.DangerousRelease (); } }
public static extern int WaitForSingleObject(SafeWaitHandle handle, int dwMilliseconds);
public static extern bool SetEvent(SafeWaitHandle handle);
static extern private bool CancelWaitableTimer( SafeWaitHandle hTimer );
static extern private bool SetWaitableTimer( SafeWaitHandle hTimer, Int64* pDue, Int32 lPeriod, IntPtr rNotify, IntPtr pArgs, bool bResume );
public static extern bool NotifyChangeEventLog(SafeHandle hEventLog, SafeWaitHandle hEvent);
public static extern bool SetWaitableTimer(SafeWaitHandle handle, ref long dueTime, int period, IntPtr mustBeZero, IntPtr mustBeZeroAlso, bool resume);
internal static int MsgWaitForMultipleObjects(SafeWaitHandle handle, bool waitAll, int milliseconds, int wakeMask) { int terminationEvent, lastWin32Error; if (handle == null) { terminationEvent = UnsafeNativeMethods.MsgWaitForMultipleObjects(0, null, waitAll, milliseconds, wakeMask); lastWin32Error = Marshal.GetLastWin32Error(); } else { RuntimeHelpers.PrepareConstrainedRegions(); bool fRelease = false; try { handle.DangerousAddRef(ref fRelease); IntPtr[] handles = { handle.DangerousGetHandle() }; terminationEvent = UnsafeNativeMethods.MsgWaitForMultipleObjects(1, handles, waitAll, milliseconds, wakeMask); lastWin32Error = Marshal.GetLastWin32Error(); } finally { if (fRelease) { handle.DangerousRelease(); } } } if (terminationEvent == NativeMethods.WAIT_FAILED) { ThrowWin32ExceptionsIfError(lastWin32Error); } return terminationEvent; }
private static extern int WaitOneNative(Microsoft.Win32.SafeHandles.SafeWaitHandle waitHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext);
[System.Security.SecuritySafeCritical] // auto-generated private void Init() { safeWaitHandle = null; waitHandle = InvalidHandle; hasThreadAffinity = false; }
/// <nodoc /> public static bool DuplicateHandle(ProcessHandle hSourceProcessHandle, SafeHandle hSourceHandle, ProcessHandle hTargetProcess, out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions) => s_nativeMethods.DuplicateHandle(hSourceProcessHandle, hSourceHandle, hTargetProcess, out targetHandle, dwDesiredAccess, bInheritHandle, dwOptions);
private static extern int SignalAndWaitOne(Microsoft.Win32.SafeHandles.SafeWaitHandle waitHandleToSignal, Microsoft.Win32.SafeHandles.SafeWaitHandle waitHandleToWaitOn, int millisecondsTimeout, bool hasThreadAffinity, bool exitContext);
internal void SetHandleInternal(Microsoft.Win32.SafeHandles.SafeWaitHandle handle) { this.safeWaitHandle = handle; this.waitHandle = handle.DangerousGetHandle(); }
private void Init() { this.safeWaitHandle = null; this.waitHandle = InvalidHandle; this.hasThreadAffinity = false; }