當前位置: 首頁>>代碼示例>>C#>>正文


C# ManualResetEvent.GetSafeWaitHandle方法代碼示例

本文整理匯總了C#中System.Threading.ManualResetEvent.GetSafeWaitHandle方法的典型用法代碼示例。如果您正苦於以下問題:C# ManualResetEvent.GetSafeWaitHandle方法的具體用法?C# ManualResetEvent.GetSafeWaitHandle怎麽用?C# ManualResetEvent.GetSafeWaitHandle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Threading.ManualResetEvent的用法示例。


在下文中一共展示了ManualResetEvent.GetSafeWaitHandle方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: UsbIOSync

        internal static bool UsbIOSync(SafeHandle dev, int code, Object inBuffer, int inSize, IntPtr outBuffer, int outSize, out int ret)
        {
            SafeOverlapped deviceIoOverlapped = new SafeOverlapped();
            ManualResetEvent hEvent = new ManualResetEvent(false);
            deviceIoOverlapped.Init(hEvent.GetSafeWaitHandle().DangerousGetHandle());
            ret = 0;

            if (!Kernel32.DeviceIoControlAsObject(dev, code, inBuffer, inSize, outBuffer, outSize, ref ret, deviceIoOverlapped.GlobalOverlapped))
            {
                int iError = Marshal.GetLastWin32Error();
                if (iError != ERROR_IO_PENDING)
                {
                    // Don't log errors for these control codes.
                    do
                    {
                        if (code == LibUsbIoCtl.GET_REG_PROPERTY) break;
                        if (code == LibUsbIoCtl.GET_CUSTOM_REG_PROPERTY) break;
                        UsbError.Error(ErrorCode.Win32Error, iError, String.Format("DeviceIoControl code {0:X8} failed:{1}", code, Kernel32.FormatSystemMessage(iError)), typeof(LibUsbDriverIO));
                    } while (false);
            #if !NETSTANDARD1_5 && !NETSTANDARD1_6
                    hEvent.Close();
            #else
                    hEvent.Dispose();
            #endif
                    return false;
                }
            }
            if (Kernel32.GetOverlappedResult(dev, deviceIoOverlapped.GlobalOverlapped, out ret, true))
            {
            #if !NETSTANDARD1_5 && !NETSTANDARD1_6
                hEvent.Close();
            #else
                hEvent.Dispose();
            #endif
                return true;
            }
            UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "GetOverlappedResult failed.\nIoCtlCode:" + code, typeof(LibUsbDriverIO));
            #if !NETSTANDARD1_5 && !NETSTANDARD1_6
            hEvent.Close();
            #else
            hEvent.Dispose();
            #endif
            return false;
        }
開發者ID:CoreCompat,項目名稱:LibUsbDotNet,代碼行數:44,代碼來源:LibUsbDriverIO.cs


注:本文中的System.Threading.ManualResetEvent.GetSafeWaitHandle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。