Ejemplo n.º 1
0
 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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public static extern Int32 WaitForSingleObject(Microsoft.Win32.SafeHandles.SafeWaitHandle handle, uint milliseconds);
Ejemplo n.º 5
0
 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)
 {
 }
Ejemplo n.º 7
0
 public static extern MMRESULT waveInOpen2(ref IntPtr hWaveIn, int deviceId, ref WAVEFORMATEX wfx, Microsoft.Win32.SafeHandles.SafeWaitHandle callBackEvent, int dwInstance, int dwFlags);
Ejemplo n.º 8
0
 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)
 {
 }
Ejemplo n.º 10
0
 public Microsoft.Win32.SafeHandles.SafeHandleMinusOneIsInvalid Watch(string path, Microsoft.Win32.SafeHandles.SafeWaitHandle event_)
 {
     XenStoreWatchHandle watch = XenStoreFunctions.xs2_watch(this.xenStoreHandle, path, event_);
     return watch;
 }
Ejemplo n.º 11
0
 public MyWaitHandle(Microsoft.Win32.SafeHandles.SafeWaitHandle swh) : base()
 {
     this.SafeWaitHandle = swh;
 }
Ejemplo n.º 12
0
 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));
 }
Ejemplo n.º 13
0
 internal static extern Int32 McGetParamPtr(UInt32 instance, UInt32 parameterId, out Microsoft.Win32.SafeHandles.SafeWaitHandle value);