DangerousRelease() private method

private DangerousRelease ( ) : void
return void
      public static ArbitraryWaitHandle FromSafeHandle(SafeHandle safeHandle) {
         Contract.Requires(safeHandle != null);
         Boolean success = false;
         try {
            safeHandle.DangerousAddRef(ref success);
            if (!success) throw new InvalidOperationException("Couldn't AddRef");

            return new ArbitraryWaitHandle(safeHandle.DangerousGetHandle());
         }
         finally {
            safeHandle.DangerousRelease();
         }
      }
Beispiel #2
0
		public static bool DuplicateHandle(HandleRef hSourceProcessHandle, SafeHandle hSourceHandle, HandleRef hTargetProcess,
			out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
		{
			bool release = false;
			try {
				hSourceHandle.DangerousAddRef (ref release);

				MonoIOError error;
				IntPtr nakedTargetHandle;
				bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.DangerousGetHandle (), hTargetProcess.Handle,
					out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);

				if (error != MonoIOError.ERROR_SUCCESS)
					throw MonoIO.GetException (error);

				targetHandle = new SafeWaitHandle (nakedTargetHandle, true);
				return ret;
			} finally {
				if (release)
					hSourceHandle.DangerousRelease ();
			}
		}
        private static IEnumerable<RecipientInfo> ToRecipientInfosForThisIndex(SafeHandle pCmsgCmsRecipientInfoMemory, int index)
        {
            bool mustRelease = false;
            pCmsgCmsRecipientInfoMemory.DangerousAddRef(ref mustRelease);
            try
            {
                unsafe
                {
                    CMSG_CMS_RECIPIENT_INFO* pCMsgCmsRecipientInfo = (CMSG_CMS_RECIPIENT_INFO*)(pCmsgCmsRecipientInfoMemory.DangerousGetHandle());
                    switch (pCMsgCmsRecipientInfo->dwRecipientChoice)
                    {
                        case CMsgCmsRecipientChoice.CMSG_KEY_TRANS_RECIPIENT:
                            return new KeyTransRecipientInfo[] { new KeyTransRecipientInfo(new KeyTransRecipientInfoPalWindows(pCmsgCmsRecipientInfoMemory, index)) };

                        case CMsgCmsRecipientChoice.CMSG_KEY_AGREE_RECIPIENT:
                            {
                                CMSG_KEY_AGREE_RECIPIENT_INFO* pCmsKeyAgreeRecipientInfo = pCMsgCmsRecipientInfo->KeyAgree;
                                int numKeys = pCmsKeyAgreeRecipientInfo->cRecipientEncryptedKeys;
                                KeyAgreeRecipientInfo[] recipients = new KeyAgreeRecipientInfo[numKeys];
                                for (int subIndex = 0; subIndex < numKeys; subIndex++)
                                {
                                    recipients[subIndex] = new KeyAgreeRecipientInfo(new KeyAgreeRecipientInfoPalWindows(pCmsgCmsRecipientInfoMemory, index, subIndex));
                                }
                                return recipients;
                            }

                        default:
                            throw ErrorCode.E_NOTIMPL.ToCryptographicException();
                    }
                }
            }
            finally
            {
                if (mustRelease)
                {
                    pCmsgCmsRecipientInfoMemory.DangerousRelease();
                }
            }
        }
 public static bool BindHandle(SafeHandle osHandle)
 {
     if (osHandle == null)
     {
         throw new ArgumentNullException("osHandle");
     }
     bool flag = false;
     bool success = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         osHandle.DangerousAddRef(ref success);
         flag = BindIOCompletionCallbackNative(osHandle.DangerousGetHandle());
     }
     finally
     {
         if (success)
         {
             osHandle.DangerousRelease();
         }
     }
     return flag;
 }
Beispiel #5
0
		public static void Unlock (SafeHandle safeHandle,
						  long position, long length,
						  out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				Unlock (safeHandle.DangerousGetHandle (), position, length, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Beispiel #6
0
		public static bool SetFileTime (SafeHandle safeHandle,
						       long creation_time,
						       long last_access_time,
						       long last_write_time,
						       out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return SetFileTime (safeHandle.DangerousGetHandle (), creation_time, last_access_time, last_write_time, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Beispiel #7
0
		public static bool SetLength (SafeHandle safeHandle,
						     long length,
						     out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return SetLength (safeHandle.DangerousGetHandle (), length, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Beispiel #8
0
		public static bool Flush (SafeHandle safeHandle,
						 out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return Flush (safeHandle.DangerousGetHandle (), out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Beispiel #9
0
		public static long Seek (SafeHandle safeHandle, long offset,
						SeekOrigin origin,
						out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return Seek (safeHandle.DangerousGetHandle (), offset, origin, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Beispiel #10
0
		public static int Write (SafeHandle safeHandle, byte [] src,
						int src_offset, int count,
						out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return Write (safeHandle.DangerousGetHandle (), src, src_offset, count, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Beispiel #11
0
		public static int Read (SafeHandle safeHandle, byte [] dest,
					       int dest_offset, int count,
					       out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return Read (safeHandle.DangerousGetHandle (), dest, dest_offset, count, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Beispiel #12
0
		static int WaitOneNative (SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
		{
			bool release = false;
			try {
#if !DISABLE_REMOTING
				if (exitContext)
					SynchronizationAttribute.ExitContext ();
#endif

				waitableSafeHandle.DangerousAddRef (ref release);

				return WaitOne_internal (waitableSafeHandle.DangerousGetHandle (), (int) millisecondsTimeout);
			} finally {
				if (release)
					waitableSafeHandle.DangerousRelease ();

#if !DISABLE_REMOTING
				if (exitContext)
					SynchronizationAttribute.EnterContext ();
#endif
			}
		}
 public static bool BindHandle(SafeHandle osHandle)
 {
     if (osHandle == null)
         throw new ArgumentNullException("osHandle");
     
     bool ret = false;
     bool mustReleaseSafeHandle = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try {
         osHandle.DangerousAddRef(ref mustReleaseSafeHandle);
         ret = BindIOCompletionCallbackNative(osHandle.DangerousGetHandle());
     }
     finally {
         if (mustReleaseSafeHandle)
             osHandle.DangerousRelease();
     }
     return ret;
 }
 internal static void SafeHandleRelease(SafeHandle pHandle)
 {
     if (pHandle == null)
     {
         throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_SafeHandle"));
     }
     try
     {
         pHandle.DangerousRelease();
     }
     catch (Exception exception)
     {
         Mda.ReportErrorSafeHandleRelease(exception);
     }
 }
Beispiel #15
0
        static internal void SafeHandleRelease(SafeHandle pHandle)
        { 
            if (pHandle == null) 
            {
                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_SafeHandle")); 
            }
            Contract.EndContractBlock();

            try 
            {
                pHandle.DangerousRelease(); 
            } 
#if MDA_SUPPORTED
            catch (Exception ex) 
            {
                Mda.ReportErrorSafeHandleRelease(ex);
            }
#else // MDA_SUPPORTED 
            catch (Exception)
            { } 
#endif // MDA_SUPPORTED 
        }
Beispiel #16
0
		static int WaitOneNative (SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
		{
#if MONOTOUCH
			if (exitContext)
				throw new NotSupportedException ("exitContext == true is not supported");
#endif

			bool release = false;
			try {
				if (exitContext)
					SynchronizationAttribute.ExitContext ();

				waitableSafeHandle.DangerousAddRef (ref release);

				return WaitOne_internal (waitableSafeHandle.DangerousGetHandle (), (int) millisecondsTimeout, exitContext);
			} finally {
				if (release)
					waitableSafeHandle.DangerousRelease ();

				if (exitContext)
					SynchronizationAttribute.EnterContext ();
			}
		}