Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Data / System / Data / ProviderBase / WrappedIUnknown.cs / 1 / 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
- Stream.cs
- ClientApiGenerator.cs
- DeclarationUpdate.cs
- ResourceCategoryAttribute.cs
- ScrollBar.cs
- WindowInteropHelper.cs
- StreamMarshaler.cs
- PrintingPermission.cs
- WebPartConnectionsCancelEventArgs.cs
- OleDbReferenceCollection.cs
- FixedElement.cs
- DocumentPageHost.cs
- ValueType.cs
- AccessText.cs
- Menu.cs
- SynchronizedInputPattern.cs
- ColumnCollection.cs
- WMIInterop.cs
- WebBrowserNavigatedEventHandler.cs
- WebPartCollection.cs
- WebServiceEnumData.cs
- TextTreeUndoUnit.cs
- InfiniteTimeSpanConverter.cs
- DurableDispatcherAddressingFault.cs
- DataKeyArray.cs
- TextViewBase.cs
- XmlSchemaCollection.cs
- AppDomainFactory.cs
- SmtpClient.cs
- WebExceptionStatus.cs
- ToolTipService.cs
- PropertyBuilder.cs
- TraceSwitch.cs
- Shape.cs
- UiaCoreApi.cs
- UiaCoreApi.cs
- Graphics.cs
- HybridDictionary.cs
- XmlSignificantWhitespace.cs
- JavaScriptSerializer.cs
- TerminatorSinks.cs
- TypeLoadException.cs
- RangeExpression.cs
- HijriCalendar.cs
- XmlArrayItemAttribute.cs
- DropDownList.cs
- CompiledELinqQueryState.cs
- DataGridViewRowsRemovedEventArgs.cs
- XmlDigitalSignatureProcessor.cs
- SqlAliaser.cs
- DocumentApplicationDocumentViewer.cs
- CounterCreationDataCollection.cs
- RecognizeCompletedEventArgs.cs
- CompilerCollection.cs
- NTAccount.cs
- CopyOnWriteList.cs
- XmlDocumentType.cs
- PersonalizationEntry.cs
- DisplayInformation.cs
- Stylesheet.cs
- RedistVersionInfo.cs
- RoutedEvent.cs
- EntityViewGenerationConstants.cs
- NoResizeSelectionBorderGlyph.cs
- Transform.cs
- IncrementalCompileAnalyzer.cs
- OdbcHandle.cs
- ObjectSecurity.cs
- BrowserCapabilitiesFactory.cs
- ToolBarPanel.cs
- ProvidePropertyAttribute.cs
- ExtensionFile.cs
- SynchronizedDispatch.cs
- TextBoxBaseDesigner.cs
- TimeSpanSecondsConverter.cs
- DesignerLoader.cs
- BreakSafeBase.cs
- DnsElement.cs
- PermissionSetEnumerator.cs
- WorkflowShape.cs
- HighContrastHelper.cs
- TokenFactoryBase.cs
- MarkupExtensionParser.cs
- IndicShape.cs
- ZipFileInfo.cs
- ProfilePropertySettingsCollection.cs
- Graph.cs
- RoutingEndpointTrait.cs
- ListSortDescription.cs
- Vertex.cs
- PKCS1MaskGenerationMethod.cs
- NavigatingCancelEventArgs.cs
- XmlnsDefinitionAttribute.cs
- ProfileSettingsCollection.cs
- PolicyManager.cs
- PageWrapper.cs
- ObjectListCommand.cs
- NumberSubstitution.cs
- XPathMessageContext.cs
- StorageInfo.cs