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


C# SafeHandle.DangerousAddRef方法代码示例

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


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

示例1: SetParent

        internal void SetParent(SafeHandle parent)
        {
            bool addedRef = false;
            parent.DangerousAddRef(ref addedRef);
            Debug.Assert(addedRef);

            _parent = parent;
        }
开发者ID:rainersigwald,项目名称:corefx,代码行数:8,代码来源:SafeInteriorHandle.cs

示例2: TransferOwnershipToParent

        internal void TransferOwnershipToParent(SafeHandle parent)
        {
            Debug.Assert(_parent == null, "Expected no existing parent");
            Debug.Assert(parent != null && !parent.IsInvalid, "Expected new parent to be non-null and valid");

            bool addedRef = false;
            parent.DangerousAddRef(ref addedRef);

            _parent = parent;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:10,代码来源:SafeBioHandle.Unix.cs

示例3: SafeProvOrNCryptKeyHandleUwp

        internal SafeProvOrNCryptKeyHandleUwp(IntPtr handle, SafeHandle parentHandle)
            : this(handle, true, true)
        {
            Debug.Assert(parentHandle != null && !parentHandle.IsClosed && !parentHandle.IsInvalid);

            // If the provided handle value wasn't valid we won't call dispose, so we shouldn't be doing this.
            Debug.Assert(!IsInvalid);

            bool addedRef = false;
            parentHandle.DangerousAddRef(ref addedRef);
            _parentHandle = parentHandle;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:SafeProvOrNCryptKeyHandleUwp.cs

示例4: FromSafeHandle

      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();
         }
      }
开发者ID:blinds52,项目名称:PowerThreading,代码行数:13,代码来源:ArbitraryWaitHandle.cs

示例5: SafePipeHandle

        internal SafePipeHandle(Socket namedPipeSocket) : base(ownsHandle: true)
        {
            Debug.Assert(namedPipeSocket != null);
            _namedPipeSocket = namedPipeSocket;

            // TODO: Issue https://github.com/dotnet/corefx/issues/6807
            // This is unfortunately the only way of getting at the Socket's file descriptor right now, until #6807 is implemented.
            PropertyInfo safeHandleProperty = s_safeHandleProperty ?? (s_safeHandleProperty = typeof(Socket).GetTypeInfo().GetDeclaredProperty("SafeHandle"));
            Debug.Assert(safeHandleProperty != null, "Socket.SafeHandle could not be found.");
            _namedPipeSocketHandle = (SafeHandle)safeHandleProperty?.GetValue(namedPipeSocket, null);

            bool ignored = false;
            _namedPipeSocketHandle.DangerousAddRef(ref ignored);
            SetHandle(_namedPipeSocketHandle.DangerousGetHandle());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:SafePipeHandle.Unix.cs

示例6: DuplicateHandle

		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 ();
			}
		}
开发者ID:BogdanovKirill,项目名称:mono,代码行数:22,代码来源:NativeMethods.cs

示例7: ToRecipientInfosForThisIndex

        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();
                }
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:39,代码来源:DecryptorPalWindows.DecodeRecipients.cs

示例8: BindHandle

 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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:ThreadPool.cs

示例9: Unlock

		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 ();
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:13,代码来源:MonoIO.cs

示例10: SetFileTime

		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 ();
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:15,代码来源:MonoIO.cs

示例11: SetLength

		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 ();
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:13,代码来源:MonoIO.cs

示例12: Flush

		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 ();
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:12,代码来源:MonoIO.cs

示例13: Seek

		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 ();
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:13,代码来源:MonoIO.cs

示例14: SafeHandleAddRef

        [System.Security.SecurityCritical]  // auto-generated
        static internal IntPtr SafeHandleAddRef(SafeHandle pHandle, ref bool success) 
        {
            if (pHandle == null) 
            { 
                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_SafeHandle"));
            } 
            Contract.EndContractBlock();

            pHandle.DangerousAddRef(ref success);
 
            return (success ? pHandle.DangerousGetHandle() : IntPtr.Zero);
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:13,代码来源:StubHelpers.cs

示例15: WaitOneNative

		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
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:22,代码来源:WaitHandle.cs


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