当前位置: 首页>>代码示例>>C#>>正文


C# SafeWaitHandle.Dispose方法代码示例

本文整理汇总了C#中Microsoft.Win32.SafeHandles.SafeWaitHandle.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SafeWaitHandle.Dispose方法的具体用法?C# SafeWaitHandle.Dispose怎么用?C# SafeWaitHandle.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Win32.SafeHandles.SafeWaitHandle的用法示例。


在下文中一共展示了SafeWaitHandle.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateMutexHandle

 private static int CreateMutexHandle(bool initiallyOwned, string name, Win32Native.SECURITY_ATTRIBUTES securityAttribute, out SafeWaitHandle mutexHandle)
 {
     bool flag = false;
     bool flag2 = false;
     bool flag3 = false;
 Label_0006:
     flag2 = false;
     flag3 = false;
     mutexHandle = Win32Native.CreateMutex(securityAttribute, initiallyOwned, name);
     int num = Marshal.GetLastWin32Error();
     if (!mutexHandle.IsInvalid || (num != 5))
     {
         return num;
     }
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         RuntimeHelpers.PrepareConstrainedRegions();
         try
         {
         }
         finally
         {
             Thread.BeginThreadAffinity();
             flag = true;
         }
         mutexHandle = Win32Native.OpenMutex(0x100001, false, name);
         if (!mutexHandle.IsInvalid)
         {
             num = 0xb7;
             if (Environment.IsW2k3)
             {
                 SafeWaitHandle handle = Win32Native.OpenMutex(0x100001, false, name);
                 if (!handle.IsInvalid)
                 {
                     RuntimeHelpers.PrepareConstrainedRegions();
                     try
                     {
                         uint num2 = 0;
                         IntPtr ptr = mutexHandle.DangerousGetHandle();
                         IntPtr ptr2 = handle.DangerousGetHandle();
                         IntPtr[] handles = new IntPtr[] { ptr, ptr2 };
                         num2 = Win32Native.WaitForMultipleObjects(2, handles, true, 0);
                         GC.KeepAlive(handles);
                         if (num2 == uint.MaxValue)
                         {
                             if (Marshal.GetLastWin32Error() != 0x57)
                             {
                                 mutexHandle.Dispose();
                                 flag3 = true;
                             }
                         }
                         else
                         {
                             flag2 = true;
                             if ((num2 >= 0) && (num2 < 2))
                             {
                                 Win32Native.ReleaseMutex(mutexHandle);
                                 Win32Native.ReleaseMutex(handle);
                             }
                             else if ((num2 >= 0x80) && (num2 < 130))
                             {
                                 Win32Native.ReleaseMutex(mutexHandle);
                                 Win32Native.ReleaseMutex(handle);
                             }
                             mutexHandle.Dispose();
                         }
                         goto Label_0166;
                     }
                     finally
                     {
                         handle.Dispose();
                     }
                 }
                 mutexHandle.Dispose();
                 flag3 = true;
             }
         }
         else
         {
             num = Marshal.GetLastWin32Error();
         }
     }
     finally
     {
         if (flag)
         {
             Thread.EndThreadAffinity();
         }
     }
 Label_0166:
     if ((flag2 || flag3) || (num == 2))
     {
         goto Label_0006;
     }
     if (num == 0)
     {
         num = 0xb7;
     }
     return num;
//.........这里部分代码省略.........
开发者ID:randomize,项目名称:VimConfig,代码行数:101,代码来源:Mutex.cs


注:本文中的Microsoft.Win32.SafeHandles.SafeWaitHandle.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。