public Semaphore(int maxCount) { SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle(CreateSemaphore(IntPtr.Zero, maxCount, maxCount, null), true); if (SafeWaitHandle.IsInvalid) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
public static bool Is64BitOperatingSystem() { if (System.IntPtr.Size * 8 == 64) { return(true); } if (!DoesWin32MethodExist(Kernel32, "IsWow64Process")) { return(false); } bool isWow64; using (Microsoft.Win32.SafeHandles.SafeWaitHandle safeHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle(System.Diagnostics.Process.GetCurrentProcess().Handle, true)) { IsWow64Process(safeHandle, out isWow64); } return(isWow64); }
public static Task <object> GetTaskFromThread(Thread th) { MethodInfo mi = typeof(Thread).GetMethod("GetNativeHandle", BindingFlags.NonPublic | BindingFlags.Instance); object thh = mi.Invoke(th, new object[0]); FieldInfo fi = thh.GetType().GetField("m_ptr", BindingFlags.NonPublic | BindingFlags.Instance); IntPtr clrhandle = (IntPtr)fi.GetValue(thh); uint nativeId = (uint)Marshal.ReadInt32(clrhandle, (IntPtr.Size == 8) ? 0x022C : 0x0160); //hack (Source: https://stackoverflow.com/a/46791587/8674428) IntPtr handle = OpenThread(ThreadAccess.SYNCHRONIZE, false, nativeId); var swh = new Microsoft.Win32.SafeHandles.SafeWaitHandle(handle, true); MyWaitHandle wh = new MyWaitHandle(swh); TaskCompletionSource <object> tcs = new TaskCompletionSource <object>(); WaitOrTimerCallback cb = (a, b) => { tcs.TrySetResult(null); }; ThreadPool.RegisterWaitForSingleObject(wh, cb, null, 999999, true); return(tcs.Task); }
public static extern Int32 WaitForSingleObject(Microsoft.Win32.SafeHandles.SafeWaitHandle handle, uint milliseconds);
internal static bool Set(Microsoft.Win32.SafeHandles.SafeWaitHandle waitHandle) => throw new NotImplementedException();
public static void SetSafeWaitHandle(this System.Threading.WaitHandle waitHandle, Microsoft.Win32.SafeHandles.SafeWaitHandle value) { }
public static extern MMRESULT waveInOpen2(ref IntPtr hWaveIn, int deviceId, ref WAVEFORMATEX wfx, Microsoft.Win32.SafeHandles.SafeWaitHandle callBackEvent, int dwInstance, int dwFlags);
private static extern int RegNotifyChangeKeyValue(IntPtr hKey, bool bWatchSubtree, RegChangeNotifyFilter dwNotifyFilter, Microsoft.Win32.SafeHandles.SafeWaitHandle hEvent, bool fAsynchronous);
void MS.Internal.Progressivity.IByteRangeDownloaderService.InitializeByteRangeDownloader(string url, string tempFile, Microsoft.Win32.SafeHandles.SafeWaitHandle eventHandle) { }
public Microsoft.Win32.SafeHandles.SafeHandleMinusOneIsInvalid Watch(string path, Microsoft.Win32.SafeHandles.SafeWaitHandle event_) { XenStoreWatchHandle watch = XenStoreFunctions.xs2_watch(this.xenStoreHandle, path, event_); return watch; }
public MyWaitHandle(Microsoft.Win32.SafeHandles.SafeWaitHandle swh) : base() { this.SafeWaitHandle = swh; }
public static void GetParam(UInt32 instance, UInt32 parameterId, out Microsoft.Win32.SafeHandles.SafeWaitHandle value) { ThrowOnMultiCamError(NativeMethods.McGetParamPtr(instance, parameterId, out value), String.Format("Cannot get parameter '{0}'", parameterId)); }
internal static extern Int32 McGetParamPtr(UInt32 instance, UInt32 parameterId, out Microsoft.Win32.SafeHandles.SafeWaitHandle value);