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
- TcpProcessProtocolHandler.cs
- PermissionListSet.cs
- WebPartZone.cs
- DataSysAttribute.cs
- fixedPageContentExtractor.cs
- Bits.cs
- SmtpClient.cs
- ErrorRuntimeConfig.cs
- figurelengthconverter.cs
- documentsequencetextview.cs
- FieldTemplateFactory.cs
- XmlRootAttribute.cs
- SHA512Managed.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- WindowsFormsSynchronizationContext.cs
- sqlmetadatafactory.cs
- UriSection.cs
- TrackingWorkflowEventArgs.cs
- AuthenticationModuleElement.cs
- RectValueSerializer.cs
- ArrayElementGridEntry.cs
- PreloadHost.cs
- TPLETWProvider.cs
- HandleExceptionArgs.cs
- NonSerializedAttribute.cs
- TypeSemantics.cs
- BitmapEffectGroup.cs
- AssemblyCollection.cs
- WebPartManagerDesigner.cs
- PolyLineSegment.cs
- MappedMetaModel.cs
- ConfigurationManagerInternal.cs
- DispatchWrapper.cs
- DesignTimeParseData.cs
- ListControlActionList.cs
- SemanticResultValue.cs
- XmlElementAttributes.cs
- ImageDrawing.cs
- MemoryFailPoint.cs
- JoinTreeNode.cs
- RouteUrlExpressionBuilder.cs
- GridSplitter.cs
- DesignerDataTableBase.cs
- CodeParameterDeclarationExpression.cs
- WebPartActionVerb.cs
- WebPartDescriptionCollection.cs
- XmlHierarchicalDataSourceView.cs
- MailHeaderInfo.cs
- ToolStripActionList.cs
- Literal.cs
- UpdateProgress.cs
- XmlNamespaceManager.cs
- HtmlLink.cs
- _ListenerAsyncResult.cs
- TrackingLocationCollection.cs
- Codec.cs
- BackStopAuthenticationModule.cs
- AssemblyBuilderData.cs
- StandardRuntimeEnumValidatorAttribute.cs
- SqlCharStream.cs
- XmlObjectSerializerReadContextComplexJson.cs
- IProvider.cs
- AcceleratedTokenProvider.cs
- ConnectionProviderAttribute.cs
- HtmlTableRow.cs
- SimpleWorkerRequest.cs
- X509AsymmetricSecurityKey.cs
- DataGridViewCellPaintingEventArgs.cs
- SHA512Managed.cs
- SecurityKeyIdentifier.cs
- ZipPackage.cs
- RelationHandler.cs
- SendActivityValidator.cs
- ParallelActivityDesigner.cs
- LocalServiceSecuritySettingsElement.cs
- BevelBitmapEffect.cs
- NonBatchDirectoryCompiler.cs
- ExcludePathInfo.cs
- ThreadPool.cs
- SByteConverter.cs
- EntityCodeGenerator.cs
- ToolBar.cs
- QueryStringParameter.cs
- WindowInteractionStateTracker.cs
- ControlBuilderAttribute.cs
- DataGridViewCellPaintingEventArgs.cs
- DataBoundControl.cs
- Calendar.cs
- EntityStoreSchemaGenerator.cs
- EntityDataSourceDataSelectionPanel.cs
- RuntimeEnvironment.cs
- LongValidator.cs
- ImageMap.cs
- ResourceManager.cs
- InputBinding.cs
- X509AsymmetricSecurityKey.cs
- PropertyFilterAttribute.cs
- FontFamily.cs
- WebBrowserNavigatedEventHandler.cs
- ProxyWebPartManagerDesigner.cs