コード例 #1
0
        public static unsafe T HandleSO <T>(Func <T> action)
        {
            var exc      = false;
            var callback = new PVECTORED_EXCEPTION_HANDLER(Handler);
            var handler  = Kernel32.AddVectoredExceptionHandler(IntPtr.Zero, callback);

            if (handler == IntPtr.Zero)
            {
                throw new Win32Exception("AddVectoredExceptionHandler failed");
            }

            var size = 32768;

            if (!Kernel32.SetThreadStackGuarantee(&size))
            {
                throw new InsufficientExecutionStackException("SetThreadStackGuarantee failed", new Win32Exception());
            }
            var result = default(T);

            try
            {
                result = action();
            }
            catch (SEHException) when((uint)Marshal.GetExceptionCode() == Err)
            {
                exc = true;
            }
            if (handler != IntPtr.Zero)
            {
                Kernel32.RemoveVectoredExceptionHandler(handler);
            }
            if (!exc)
            {
                return(result);
            }
            if (Msvcrt._resetstkoflw() == 0)
            {
                throw new InvalidOperationException("_resetstkoflw failed");
            }
            throw new StackOverflowException();
        }
コード例 #2
0
ファイル: Methods.cs プロジェクト: shijiaxing/Win32Interop
 public static extern IntPtr AddVectoredExceptionHandler(uint First, PVECTORED_EXCEPTION_HANDLER Handler);
コード例 #3
0
 public static extern IntPtr AddVectoredExceptionHandler(IntPtr FirstHandler, PVECTORED_EXCEPTION_HANDLER VectoredHandler);
コード例 #4
0
 public static void AddCustomVectoredExceptionHandler(PVECTORED_EXCEPTION_HANDLER handler)
 {
     VectoredExceptionHandlers.Add(handler);
 }