Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Core / System / Windows / Media / SafeMILHandle.cs / 1 / SafeMILHandle.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // A safe way to deal with unmanaged MIL interface pointers. //--------------------------------------------------------------------------- using System; using System.IO; using System.Security; using System.Security.Permissions; using System.Collections; using System.Reflection; using MS.Internal; using MS.Win32; using System.Diagnostics; using System.Windows.Media; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; using UnsafeNativeMethods=MS.Win32.PresentationCore.UnsafeNativeMethods; namespace System.Windows.Media { internal class SafeMILHandle : SafeHandleZeroOrMinusOneIsInvalid { ////// Use this constructor if the handle isn't ready yet and later /// set the handle with SetHandle. SafeMILHandle owns the release /// of the handle. /// ////// Critical: This derives from a class that has a link demand and inheritance demand /// TreatAsSafe: Ok to call constructor /// [SecurityCritical,SecurityTreatAsSafe] internal SafeMILHandle() : base(true) { } ////// Use this constructor if the handle exists at construction time. /// SafeMILHandle owns the release of the parameter. /// ////// Critical: This code calls UpdateEstimatedSize. /// It is used to keep memory around /// [SecurityCritical] internal SafeMILHandle(IntPtr handle, long estimatedSize) : base(true) { SetHandle(handle); // // Hint the GC at the size of the unmanaged memory associated with // this object. We release pressure in the finalizer. // UpdateEstimatedSize(estimatedSize); } ////// Change our size to the new size specified /// ////// Critical: This code calls into AddMemoryPressure and RemoveMemoryPressure /// both of which have link demands. It is used to keep memory around /// [SecurityCritical] internal void UpdateEstimatedSize(long estimatedSize) { if (_gcPressure > 0) { MemoryPressure.Remove(_gcPressure); } _gcPressure = estimatedSize; if (_gcPressure > 0) { MemoryPressure.Add(_gcPressure); } } ////// Critical - calls unmanaged code, not treat as safe because you must /// validate that handle is a valid COM object. /// [SecurityCritical] protected override bool ReleaseHandle() { UnsafeNativeMethods.MILUnknown.ReleaseInterface(ref handle); // // We've released the unmanaged memory, so remove associated // GC pressure. // UpdateEstimatedSize(0); return true; } // // Estimated size in bytes of the unmanaged memory we are holding onto // private long _gcPressure; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WindowsImpersonationContext.cs
- DataGridViewAutoSizeModeEventArgs.cs
- RenameRuleObjectDialog.Designer.cs
- ProcessInfo.cs
- ExpressionsCollectionEditor.cs
- MediaContextNotificationWindow.cs
- WindowsRebar.cs
- PrintDialogException.cs
- SoapRpcServiceAttribute.cs
- DataViewManager.cs
- ImageFormatConverter.cs
- XmlCountingReader.cs
- RuntimeIdentifierPropertyAttribute.cs
- OracleConnectionStringBuilder.cs
- SoapIncludeAttribute.cs
- ClientTargetSection.cs
- CompatibleIComparer.cs
- Column.cs
- ArrayExtension.cs
- PointLightBase.cs
- ApplicationException.cs
- DefaultAsyncDataDispatcher.cs
- SplitContainer.cs
- SystemThemeKey.cs
- BasicDesignerLoader.cs
- XPathEmptyIterator.cs
- UniqueEventHelper.cs
- DataGridViewTopRowAccessibleObject.cs
- OdbcConnectionFactory.cs
- WebPartManager.cs
- EdmToObjectNamespaceMap.cs
- ListViewSortEventArgs.cs
- PocoPropertyAccessorStrategy.cs
- DrawingAttributes.cs
- MediaPlayer.cs
- WinInet.cs
- Base64Stream.cs
- WrappedIUnknown.cs
- CollaborationHelperFunctions.cs
- PagerSettings.cs
- TypeInfo.cs
- CodeCastExpression.cs
- TextElementEnumerator.cs
- NameValueFileSectionHandler.cs
- OledbConnectionStringbuilder.cs
- ObjectStateEntry.cs
- ZoneLinkButton.cs
- CollectionConverter.cs
- UriScheme.cs
- DataGridComponentEditor.cs
- MessageQueuePermissionEntry.cs
- SrgsText.cs
- RowToFieldTransformer.cs
- FormsAuthenticationUserCollection.cs
- WebRequestModulesSection.cs
- ContextMenuService.cs
- TransactionTraceIdentifier.cs
- FrameworkName.cs
- NullableConverter.cs
- IListConverters.cs
- FileDataSourceCache.cs
- RichTextBox.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- XmlToDatasetMap.cs
- SessionEndingCancelEventArgs.cs
- XhtmlBasicListAdapter.cs
- CompiledELinqQueryState.cs
- XPathNavigatorKeyComparer.cs
- ToolStripPanel.cs
- DataTableMappingCollection.cs
- OdbcException.cs
- ScriptManager.cs
- WebPartUtil.cs
- DecimalAnimationBase.cs
- TextRunTypographyProperties.cs
- AlignmentYValidation.cs
- WindowsAltTab.cs
- ItemsChangedEventArgs.cs
- DataBinding.cs
- XmlArrayAttribute.cs
- View.cs
- DashStyle.cs
- XsltContext.cs
- ResourceContainer.cs
- ObjectToIdCache.cs
- Guid.cs
- LifetimeServices.cs
- SqlClientWrapperSmiStreamChars.cs
- DesignerResources.cs
- RoutedEventHandlerInfo.cs
- Closure.cs
- ImageBrush.cs
- ClassicBorderDecorator.cs
- InputManager.cs
- PreProcessor.cs
- Buffer.cs
- WmlPanelAdapter.cs
- _ContextAwareResult.cs
- SemanticBasicElement.cs
- PtsPage.cs