internal static extern bool DuplicateHandle( SafeProcessHandle hSourceProcessHandle, SafeHandle hSourceHandle, SafeProcessHandle hTargetProcess, out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions );
public static void SafeWaitHandleExtensions_set() { var wh = new MyWaitHandle(); var swhExpected = new SafeWaitHandle(new IntPtr(5), true); wh.SetSafeWaitHandle(swhExpected); var swh = wh.GetSafeWaitHandle(); Assert.Equal(swhExpected, swh); wh.SetSafeWaitHandle(null); swh = wh.GetSafeWaitHandle(); Assert.NotNull(swh); Assert.Equal(new IntPtr(-1), swh.DangerousGetHandle()); }
private Mutex(SafeWaitHandle handle) { SafeWaitHandle = handle; }
public static void SetSafeWaitHandle(this WaitHandle waitHandle, SafeWaitHandle value);
private EventWaitHandle(SafeWaitHandle handle) { SetHandleInternal(handle); }
public static extern int CloseHandle(SafeWaitHandle handle);
public static extern bool QueryFullProcessImageName(SafeWaitHandle handle, ImageNameType type, StringBuilder imagePath, ref int size);
internal static extern bool TerminateJobObject(SafeWaitHandle hJob, int exitCode);
public static void SafeWaitHandle_invalid() { SafeWaitHandle swh = new SafeWaitHandle(IntPtr.Zero, false); Assert.Equal(false, swh.IsClosed); Assert.Equal(true, swh.IsInvalid); }
public static extern Int32 WaitForSingleObject(SafeWaitHandle hHandle, Int32 dwMilliseconds);
internal extern static uint ResumeThread(SafeWaitHandle hThread);
internal extern static ThreadPriority GetThreadPriority(SafeWaitHandle hThread);
public static extern bool OpenProcessToken(SafeWaitHandle hProcess, TokenAccessMask accessMask, out SafeTokenHandle handle);
internal static extern int WaitForSingleObject(SafeWaitHandle handle, int timeout);
public static extern bool SetWaitableTimer(SafeWaitHandle handle, ref long dueTime, int period, IntPtr mustBeZero, IntPtr mustBeZeroAlso, bool resume);
internal static extern bool ReleaseSemaphore(SafeWaitHandle handle, int releaseCount, out int previousCount);
public static extern ProcessPriorityClass GetPriorityClass(SafeWaitHandle hProcess);
internal extern static bool SetThreadPriority(SafeWaitHandle hThread, int nPriority);
public static void SafeWaitHandle_valid() { SafeWaitHandle swh = new SafeWaitHandle(new IntPtr(1), true); Assert.Equal(false, swh.IsClosed); Assert.Equal(false, swh.IsInvalid); }
public static extern int GetProcessId(SafeWaitHandle hProcess);
/// <inheritdoc /> public bool DuplicateHandle(ProcessHandle hSourceProcessHandle, SafeHandle hSourceHandle, ProcessHandle hTargetProcess, out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions) => throw new NotImplementedException();
public static extern bool IsProcessInJob(SafeHandle hProcess, SafeWaitHandle hJob, out bool inJob);
/// <inheritdoc /> public bool DuplicateHandle(ProcessHandle hSourceProcessHandle, SafeHandle hSourceHandle, ProcessHandle hTargetProcess, out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions) => ExternDuplicateHandle(hSourceProcessHandle, hSourceHandle, hTargetProcess, out targetHandle, dwDesiredAccess, bInheritHandle, dwOptions);
internal static extern bool CheckRemoteDebuggerPresent(SafeWaitHandle hProcess, out bool beingDebugged);
private static extern Boolean QueryThreadCycleTime(SafeWaitHandle threadHandle, out UInt64 CycleTime);
public unsafe EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity) { if (null != name && System.IO.Path.MAX_PATH < name.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name)); } Contract.EndContractBlock(); Win32Native.SECURITY_ATTRIBUTES secAttrs = null; #if !MONO #if FEATURE_MACL // For ACL's, get the security descriptor from the EventWaitHandleSecurity. if (eventSecurity != null) { secAttrs = new Win32Native.SECURITY_ATTRIBUTES(); secAttrs.nLength = (int)Marshal.SizeOf(secAttrs); byte[] sd = eventSecurity.GetSecurityDescriptorBinaryForm(); byte * pSecDescriptor = stackalloc byte[sd.Length]; Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length); secAttrs.pSecurityDescriptor = pSecDescriptor; } #endif #endif SafeWaitHandle _handle = null; Boolean isManualReset; switch (mode) { case EventResetMode.ManualReset: isManualReset = true; break; case EventResetMode.AutoReset: isManualReset = false; break; default: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", name)); } ; #if MONO int errorCode; _handle = new SafeWaitHandle(NativeEventCalls.CreateEvent_internal(isManualReset, initialState, name, out errorCode), true); #else _handle = Win32Native.CreateEvent(secAttrs, isManualReset, initialState, name); int errorCode = Marshal.GetLastWin32Error(); #endif if (_handle.IsInvalid) { _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); } createdNew = errorCode != Win32Native.ERROR_ALREADY_EXISTS; SetHandleInternal(_handle); }
private static extern Boolean QueryProcessCycleTime(SafeWaitHandle processHandle, out UInt64 CycleTime);
public static extern bool ResetEvent(SafeWaitHandle handle);
private CycleTime(Boolean trackingThreadTime, SafeWaitHandle handle) { m_trackingThreadTime = trackingThreadTime; m_handle = handle; m_startCycleTime = m_trackingThreadTime ? Thread() : Process(m_handle); }
internal static extern bool SetPacketEvent(DriverHandle hOpen, IntPtr hAdapter, SafeWaitHandle hWin32Event);
public static CycleTime StartThread(SafeWaitHandle threadHandle) { return(new CycleTime(true, threadHandle)); }
public static CycleTime StartProcess(SafeWaitHandle processHandle) { return(new CycleTime(false, processHandle)); }
int waveOutOpen( out IntPtr waveOutHandle, int deviceId, WAVEFORMATEX format, SafeWaitHandle event_handle, int instanceData, int flags );
internal MutexCleanupInfo(SafeWaitHandle mutexHandle, bool inCriticalRegion) { this.mutexHandle = mutexHandle; this.inCriticalRegion = inCriticalRegion; }
internal extern static uint Icmp6SendEcho2(SafeCloseIcmpHandle icmpHandle, SafeWaitHandle Event, IntPtr apcRoutine, IntPtr apcContext, byte[] sourceSocketAddress, byte[] destSocketAddress, [In] SafeLocalAllocHandle data, ushort dataSize, ref IPOptions options, SafeLocalAllocHandle replyBuffer, uint replySize, uint timeout);
private Mutex(SafeWaitHandle handle) { SetHandleInternal(handle); hasThreadAffinity = true; }
private static int CreateMutexHandle(bool initiallyOwned, String name, Win32Native.SECURITY_ATTRIBUTES securityAttribute, out SafeWaitHandle mutexHandle) { int errorCode; while (true) { mutexHandle = Win32Native.CreateMutex(securityAttribute, initiallyOwned, name); errorCode = Marshal.GetLastWin32Error(); if (!mutexHandle.IsInvalid) { break; } if (errorCode != Win32Native.ERROR_ACCESS_DENIED) { break; } // If a mutex with the name already exists, OS will try to open it with FullAccess. // It might fail if we don't have enough access. In that case, we try to open the mutex will modify and synchronize access. RuntimeHelpers.PrepareConstrainedRegions(); mutexHandle = Win32Native.OpenMutex( Win32Native.MUTEX_MODIFY_STATE | Win32Native.SYNCHRONIZE, false, name); errorCode = !mutexHandle.IsInvalid ? Win32Native.ERROR_ALREADY_EXISTS : Marshal.GetLastWin32Error(); // There could be a race condition here, the other owner of the mutex can free the mutex, // We need to retry creation in that case. if (errorCode != Win32Native.ERROR_FILE_NOT_FOUND) { if (errorCode == Win32Native.ERROR_SUCCESS) { errorCode = Win32Native.ERROR_ALREADY_EXISTS; } break; } } return(errorCode); }
public static extern IntPtr EvtSubscribe( IntPtr session, SafeWaitHandle signalEvent, [MarshalAs(UnmanagedType.LPWStr)]string path, [MarshalAs(UnmanagedType.LPWStr)]string query, IntPtr bookmark, IntPtr context, IntPtr callback, int flags);