本文整理汇总了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;
}