Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / ProviderBase / WrappedIUnknown.cs / 1305376 / WrappedIUnknown.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.ProviderBase { using System; using System.Data.Common; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; using System.Threading; // We wrap the interface as a native IUnknown IntPtr so that every // thread that creates a connection will fake the correct context when // in transactions, otherwise everything is marshalled. We do this // for two reasons: first for the connection pooler, this is a significant // performance gain, second for the OLE DB provider, it doesn't marshal. internal class WrappedIUnknown : SafeHandle { internal WrappedIUnknown() : base(IntPtr.Zero, true) { } internal WrappedIUnknown(object unknown) : this() { if (null != unknown) { RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { base.handle = Marshal.GetIUnknownForObject(unknown); // } } } public override bool IsInvalid { get { return (IntPtr.Zero == base.handle); } } internal object ComWrapper() { // NOTE: Method, instead of property, to avoid being evaluated at // runtime in the debugger. object value = null; bool mustRelease = false; RuntimeHelpers.PrepareConstrainedRegions(); try { DangerousAddRef(ref mustRelease); IntPtr handle = DangerousGetHandle(); value = System.Runtime.Remoting.Services.EnterpriseServicesHelper.WrapIUnknownWithComObject(handle); } finally { if (mustRelease) { DangerousRelease(); } } return value; } override protected bool ReleaseHandle() { // NOTE: The SafeHandle class guarantees this will be called exactly once. IntPtr ptr = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != ptr) { Marshal.Release(ptr); } return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlEnumAttribute.cs
- ExtendedProtectionPolicyElement.cs
- CompoundFileReference.cs
- GroupBoxAutomationPeer.cs
- NativeActivityFaultContext.cs
- RequestUriProcessor.cs
- StatusBar.cs
- ConnectionPoolManager.cs
- SqlLiftIndependentRowExpressions.cs
- ExtensionSimplifierMarkupObject.cs
- BrowserCapabilitiesFactoryBase.cs
- CompilerErrorCollection.cs
- altserialization.cs
- Policy.cs
- ListViewDeletedEventArgs.cs
- NamespaceInfo.cs
- FilterableAttribute.cs
- MenuRendererClassic.cs
- DebugControllerThread.cs
- XmlSchemaComplexType.cs
- MetadataUtil.cs
- ReadOnlyDataSource.cs
- Completion.cs
- PropertyItemInternal.cs
- ServiceManager.cs
- LinqDataSourceHelper.cs
- WebPartsPersonalizationAuthorization.cs
- ToolStripManager.cs
- RenderDataDrawingContext.cs
- InstanceHandle.cs
- PropertyDescriptors.cs
- Inline.cs
- System.Data_BID.cs
- IgnoreFileBuildProvider.cs
- Set.cs
- Fault.cs
- Assert.cs
- ListChunk.cs
- FirstMatchCodeGroup.cs
- DataServiceQuery.cs
- Completion.cs
- XamlTreeBuilder.cs
- _DomainName.cs
- Attributes.cs
- PropertyNames.cs
- WebHttpElement.cs
- entityreference_tresulttype.cs
- BitmapEffectGeneralTransform.cs
- XPathParser.cs
- FacetDescriptionElement.cs
- CAGDesigner.cs
- BitStream.cs
- FilterableAttribute.cs
- GridItemCollection.cs
- ListViewUpdateEventArgs.cs
- ValidatedControlConverter.cs
- CancellableEnumerable.cs
- X509Certificate.cs
- TagPrefixCollection.cs
- PathTooLongException.cs
- Int64.cs
- TextEndOfLine.cs
- RequestUriProcessor.cs
- RNGCryptoServiceProvider.cs
- CompilerCollection.cs
- BaseDataList.cs
- EventLog.cs
- XsdValidatingReader.cs
- ListViewGroup.cs
- FastPropertyAccessor.cs
- UrlParameterWriter.cs
- BitmapCodecInfo.cs
- SafePointer.cs
- basenumberconverter.cs
- EncryptedReference.cs
- HttpApplicationFactory.cs
- SpnegoTokenProvider.cs
- RequestCacheManager.cs
- WorkflowCommandExtensionItem.cs
- MsmqReceiveParameters.cs
- HttpWebResponse.cs
- EasingFunctionBase.cs
- PhonemeConverter.cs
- MetadataUtilsSmi.cs
- SqlCacheDependency.cs
- ListItem.cs
- AsyncCompletedEventArgs.cs
- WorkflowView.cs
- OperationCanceledException.cs
- KeySpline.cs
- Int32CAMarshaler.cs
- cookiecollection.cs
- graph.cs
- DataColumnMappingCollection.cs
- XmlMtomWriter.cs
- XmlSchemaInfo.cs
- DocumentGrid.cs
- SignedXml.cs
- DataGridViewDataConnection.cs
- DataGridViewRow.cs