Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ //// 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
- PrintDialog.cs
- SByte.cs
- NumericUpDownAcceleration.cs
- M3DUtil.cs
- Mappings.cs
- Section.cs
- EdmTypeAttribute.cs
- WebPartCatalogAddVerb.cs
- MemberCollection.cs
- StylusButtonCollection.cs
- EntityDataSourceUtil.cs
- LayoutEvent.cs
- NTAccount.cs
- SafeRightsManagementPubHandle.cs
- TreeViewImageIndexConverter.cs
- SafeEventHandle.cs
- UnitySerializationHolder.cs
- COM2FontConverter.cs
- SqlDataSourceConfigureSelectPanel.cs
- HttpCachePolicyElement.cs
- LayoutInformation.cs
- CombinedGeometry.cs
- FragmentQueryProcessor.cs
- Control.cs
- ApplicationBuildProvider.cs
- MessageAction.cs
- BaseCollection.cs
- OleDbError.cs
- SecurityKeyUsage.cs
- TypefaceCollection.cs
- Transform3DGroup.cs
- IndentedTextWriter.cs
- SafeBitVector32.cs
- Popup.cs
- SynchronizedInputHelper.cs
- WindowsRichEditRange.cs
- DataGridViewCellStateChangedEventArgs.cs
- SectionXmlInfo.cs
- X509SecurityTokenProvider.cs
- Int16Storage.cs
- TakeQueryOptionExpression.cs
- ParseHttpDate.cs
- DragEventArgs.cs
- SiteIdentityPermission.cs
- WebPermission.cs
- ResourceManagerWrapper.cs
- Match.cs
- Knowncolors.cs
- ListenerConfig.cs
- SymmetricAlgorithm.cs
- XmlUnspecifiedAttribute.cs
- XmlUrlEditor.cs
- TypeConverterValueSerializer.cs
- PopupEventArgs.cs
- VolatileEnlistmentMultiplexing.cs
- StretchValidation.cs
- MouseEvent.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- TraceLevelStore.cs
- WebPart.cs
- RootBrowserWindowProxy.cs
- DataTrigger.cs
- FileUpload.cs
- XsltLoader.cs
- ExecutionEngineException.cs
- SrgsElement.cs
- PolyLineSegment.cs
- HttpFileCollectionBase.cs
- BitmapSourceSafeMILHandle.cs
- FigureParagraph.cs
- SHA1.cs
- OperatingSystem.cs
- StreamReader.cs
- WebMessageFormatHelper.cs
- ProfileSection.cs
- WorkflowFormatterBehavior.cs
- Transactions.cs
- DesignUtil.cs
- UnsafeNativeMethodsTablet.cs
- VisualTarget.cs
- ClientEventManager.cs
- ExcCanonicalXml.cs
- Stacktrace.cs
- BulletedListEventArgs.cs
- CornerRadius.cs
- EntityViewContainer.cs
- EditingCoordinator.cs
- WpfWebRequestHelper.cs
- HtmlInputSubmit.cs
- InkCollectionBehavior.cs
- OutputCacheSettings.cs
- X509Certificate2Collection.cs
- HashHelper.cs
- OleDbEnumerator.cs
- WorkflowElementDialog.cs
- XmlException.cs
- LayoutEditorPart.cs
- FigureHelper.cs
- AssemblyResourceLoader.cs
- WorkflowApplicationUnhandledExceptionEventArgs.cs