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


C# SafeWaitHandle.DangerousGetHandle方法代码示例

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


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

示例1: ResetEvent

		public static bool ResetEvent (SafeWaitHandle handle)
		{
			bool release = false;
			try {
				handle.DangerousAddRef (ref release);
				return ResetEvent_internal (handle.DangerousGetHandle ());
			} finally {
				if (release)
					handle.DangerousRelease ();
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:11,代码来源:NativeEventCalls.cs

示例2: MsgWaitForMultipleObjects

 internal static int MsgWaitForMultipleObjects(SafeWaitHandle handle, bool waitAll, int milliseconds, int wakeMask)
 {
     int terminationEvent, lastWin32Error;
     if (handle == null)
     {
         terminationEvent = UnsafeNativeMethods.MsgWaitForMultipleObjects(0, null, waitAll, milliseconds, wakeMask);
         lastWin32Error = Marshal.GetLastWin32Error();
     }
     else
     {
         RuntimeHelpers.PrepareConstrainedRegions();
         bool fRelease = false;
         try
         {
             handle.DangerousAddRef(ref fRelease);
             IntPtr[] handles = { handle.DangerousGetHandle() };
             terminationEvent = UnsafeNativeMethods.MsgWaitForMultipleObjects(1, handles, waitAll, milliseconds, wakeMask);
             lastWin32Error = Marshal.GetLastWin32Error();
         }
         finally
         {
             if (fRelease)
             {
                 handle.DangerousRelease();
             }
         }
     }
     if (terminationEvent == NativeMethods.WAIT_FAILED)
     {
         ThrowWin32ExceptionsIfError(lastWin32Error);
     }
     return terminationEvent;
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:33,代码来源:Misc.cs

示例3: SetHandleInternal

 internal void SetHandleInternal(SafeWaitHandle handle)
 {
     safeWaitHandle = handle;
     waitHandle = handle.DangerousGetHandle();
 }
开发者ID:uQr,项目名称:referencesource,代码行数:5,代码来源:waithandle.cs

示例4: WaitOneNative

        internal static int WaitOneNative(SafeWaitHandle waitableSafeHandle, long millisecondsTimeout)
        {
            Debug.Assert(millisecondsTimeout >= -1 && millisecondsTimeout <= int.MaxValue);

            waitableSafeHandle.DangerousAddRef();
            try
            {
                return LowLevelThread.WaitForSingleObject(waitableSafeHandle.DangerousGetHandle(), (int)millisecondsTimeout);
            }
            finally
            {
                waitableSafeHandle.DangerousRelease();
            }
        }
开发者ID:nattress,项目名称:corert,代码行数:14,代码来源:WaitHandle.cs

示例5: ResumeThread

 public void ResumeThread(SafeWaitHandle threadHandle)
 {
     ResumeThread(threadHandle.DangerousGetHandle());
 }
开发者ID:nektra,项目名称:Deviare-InProc,代码行数:4,代码来源:DeviareLite.cs

示例6: SignalAndWaitOne

		static int SignalAndWaitOne (SafeWaitHandle waitHandleToSignal,SafeWaitHandle waitHandleToWaitOn, int millisecondsTimeout, bool hasThreadAffinity,  bool exitContext)
		{
			bool releaseHandleToSignal = false, releaseHandleToWaitOn = false;
			try {
				waitHandleToSignal.DangerousAddRef (ref releaseHandleToSignal);
				waitHandleToWaitOn.DangerousAddRef (ref releaseHandleToWaitOn);

				return SignalAndWait_Internal (waitHandleToSignal.DangerousGetHandle (), waitHandleToWaitOn.DangerousGetHandle (), millisecondsTimeout);
			} finally {
				if (releaseHandleToSignal)
					waitHandleToSignal.DangerousRelease ();
				if (releaseHandleToWaitOn)
					waitHandleToWaitOn.DangerousRelease ();
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:15,代码来源:WaitHandle.cs

示例7: CreateProcessInJob

        /// <summary>
        /// Create a process and attach it to a job.  The process is resumed
        /// by the time the call returns if the call was successful.
        /// </summary>
        /// <param name="ExeFileName">Supplies the fully qualified exe file
        /// name of the main process image.</param>
        /// <param name="CommandLine">Supplies command line arguments that do
        /// not include the implicit exe file name argument.</param>
        /// <param name="Job">Supplies a job handle.</param>
        /// <param name="BreakawayOk">Supplies true if job breakaway is to be
        /// considered acceptable.</param>
        /// <returns>A System.Diagnostics.Process describing the created
        /// process object.</returns>
        private static Process CreateProcessInJob(string ExeFileName, string CommandLine, SafeWaitHandle Job, bool BreakawayOk = false)
        {
            PROCESS_INFORMATION ProcessInfo;
            STARTUPINFO StartupInfo;
            bool Succeeded = false;

            ProcessInfo.hProcess = IntPtr.Zero;
            ProcessInfo.hThread = IntPtr.Zero;

            StartupInfo.cb = 0;
            StartupInfo.lpReserved = null;
            StartupInfo.lpDesktop = null;
            StartupInfo.lpTitle = null;
            StartupInfo.dwX = 0;
            StartupInfo.dwY = 0;
            StartupInfo.dwXSize = 0;
            StartupInfo.dwYSize = 0;
            StartupInfo.dwXCountChars = 0;
            StartupInfo.dwYCountChars = 0;
            StartupInfo.dwFillAttribute = 0;
            StartupInfo.dwFlags = (UInt32)STARTFLAGS.UseShowWindow;
            StartupInfo.wShowWindow = (UInt16)SHOWCMD.SW_HIDE;
            StartupInfo.cbReserved2 = 0;
            StartupInfo.lpReserved2 = IntPtr.Zero;
            StartupInfo.hStdInput = IntPtr.Zero;
            StartupInfo.hStdOutput = IntPtr.Zero;
            StartupInfo.hStdError = IntPtr.Zero;

            StartupInfo.cb = Marshal.SizeOf(StartupInfo);

            try
            {
                string RealCommandLine = String.Format("\"{0}\" {1}", ExeFileName, CommandLine);
                bool BreakawayTried = false;

                //
                // Create the process.
                //

                for (; ; )
                {
                    if (CreateProcessA(ExeFileName,
                        CommandLine,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        0,
                        PROCESSCREATIONFLAGS.CreateSuspended | (BreakawayOk && !BreakawayTried ? PROCESSCREATIONFLAGS.CreateBreakawayFromJob : 0),
                        IntPtr.Zero,
                        null,
                        ref StartupInfo,
                        out ProcessInfo) == 0)
                    {
                        int LastError = Marshal.GetLastWin32Error();

                        ProcessInfo.hProcess = IntPtr.Zero;
                        ProcessInfo.hThread = IntPtr.Zero;

                        if ((LastError == ERROR_ACCESS_DENIED) && (BreakawayOk) && (!BreakawayTried))
                        {
                            Logger.Log("DatabaseConnector.CreateProcessInJob: Failed to create process with breakaway due to ERROR_ACCESS_DENIED, trying again without breakaway.");
                            BreakawayTried = true;
                            continue;
                        }

                        throw new ApplicationException(String.Format("CreateProcessA(ExeFileName = '{0}', CommandLine = '{1}') failed: {2}",
                            ExeFileName,
                            CommandLine,
                            LastError));
                    }

                    break;
                }

                //
                // Join it to the job so that it will be cleaned up if the
                // nwn2server process exits unexpectedly.
                //

                if (AssignProcessToJobObject(Job.DangerousGetHandle(), ProcessInfo.hProcess) == 0)
                {
                    int LastError = Marshal.GetLastWin32Error();
                    bool ContinueAnyway = false;

                    if (LastError == ERROR_ACCESS_DENIED)
                    {
                        if (BreakawayOk == false)
                        {
//.........这里部分代码省略.........
开发者ID:ALandFarAway,项目名称:ALFA-Base-Resources,代码行数:101,代码来源:DatabaseConnector.cs

示例8: ConfigureJob

        /// <summary>
        /// Configure a job object for use by the database connector.  It is
        /// set up so that once the last job handle lapses, all of the
        /// processes joined to the job are terminated.
        /// </summary>
        /// <param name="Job">Supplies a job object handle.</param>
        private static void ConfigureJob(SafeWaitHandle Job)
        {
            JOBOBJECT_EXTENDED_LIMIT_INFORMATION ExtendedLimit;

            ExtendedLimit.BasicLimitInformation.PerProcessUserTimeLimit = 0;
            ExtendedLimit.BasicLimitInformation.PerJobUserTimeLimit = 0;
            ExtendedLimit.BasicLimitInformation.LimitFlags = 0;
            ExtendedLimit.BasicLimitInformation.MinimumWorkingSetSize = UIntPtr.Zero;
            ExtendedLimit.BasicLimitInformation.MaximumWorkingSetSize = UIntPtr.Zero;
            ExtendedLimit.BasicLimitInformation.ActiveProcessLimit = 0;
            ExtendedLimit.BasicLimitInformation.Affinity = UIntPtr.Zero;
            ExtendedLimit.BasicLimitInformation.PriorityClass = 0;
            ExtendedLimit.BasicLimitInformation.SchedulingClass = 0;
            ExtendedLimit.IoInfo.ReadOperationCount = 0;
            ExtendedLimit.IoInfo.WriteOperationCount = 0;
            ExtendedLimit.IoInfo.OtherOperationCount = 0;
            ExtendedLimit.IoInfo.ReadTransferCount = 0;
            ExtendedLimit.IoInfo.WriteTransferCount = 0;
            ExtendedLimit.IoInfo.OtherTransferCount = 0;
            ExtendedLimit.ProcessMemoryLimit = UIntPtr.Zero;
            ExtendedLimit.JobMemoryLimit = UIntPtr.Zero;
            ExtendedLimit.PeakProcessMemoryUsed = UIntPtr.Zero;
            ExtendedLimit.PeakJobMemoryUsed = UIntPtr.Zero;

            //
            // Set the job to terminate all contained processes on last handle
            // close (for the job itself), and to terminate all processes that
            // are in the job and which have an unhandled exception in lieu of
            // blocking them on the hard error dialog box.
            //

            ExtendedLimit.BasicLimitInformation.LimitFlags = JOBOBJECTLIMIT.KillOnJobClose | JOBOBJECTLIMIT.DieOnUnhandledException;

            int LimitSize = Marshal.SizeOf(ExtendedLimit);
            IntPtr JobInformation = Marshal.AllocHGlobal(LimitSize);

            try
            {
                Marshal.StructureToPtr(ExtendedLimit, JobInformation, false);

                if (SetInformationJobObject(Job.DangerousGetHandle(),
                    JOBOBJECTINFOCLASS.ExtendedLimitInformation,
                    JobInformation,
                    (uint)LimitSize) == 0)
                {
                    throw new ApplicationException("SetInformationJobObject failed: " + Marshal.GetLastWin32Error());
                }
            }
            finally
            {
                Marshal.FreeHGlobal(JobInformation);
            }
        }
开发者ID:ALandFarAway,项目名称:ALFA-Base-Resources,代码行数:59,代码来源:DatabaseConnector.cs

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