Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Shared / MS / Internal / AppDomainShutdownMonitor.cs / 1 / AppDomainShutdownMonitor.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // Implement IAddDomainShutdownListener and use AppDomainShutdownMonitor // to know when the AppDomain is going down // //--------------------------------------------------------------------------- using System; using System.Diagnostics; // Assert using System.Collections.Generic; // Dictionary using System.Threading; // [ThreadStatic] namespace MS.Internal { internal interface IAppDomainShutdownListener { void NotifyShutdown(); } internal static class AppDomainShutdownMonitor { static AppDomainShutdownMonitor() { AppDomain.CurrentDomain.DomainUnload += OnShutdown; AppDomain.CurrentDomain.ProcessExit += OnShutdown; _dictionary = new Dictionary(); } public static void Add(WeakReference listener) { Debug.Assert(listener.Target != null); Debug.Assert(listener.Target is IAppDomainShutdownListener); lock (_dictionary) { if (!_shuttingDown) { _dictionary.Add(listener, listener); } } } public static void Remove(WeakReference listener) { Debug.Assert(listener.Target == null || listener.Target is IAppDomainShutdownListener); lock (_dictionary) { if (!_shuttingDown) { _dictionary.Remove(listener); } } } private static void OnShutdown(object sender, EventArgs e) { lock (_dictionary) { // Setting this to true prevents Add and Remove from modifying the list. This // way we call out without holding a lock (which would be bad) _shuttingDown = true; } foreach (WeakReference value in _dictionary.Values) { IAppDomainShutdownListener listener = value.Target as IAppDomainShutdownListener; if (listener != null) { listener.NotifyShutdown(); } } } private static Dictionary _dictionary; private static bool _shuttingDown; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // // Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // Implement IAddDomainShutdownListener and use AppDomainShutdownMonitor // to know when the AppDomain is going down // //--------------------------------------------------------------------------- using System; using System.Diagnostics; // Assert using System.Collections.Generic; // Dictionary using System.Threading; // [ThreadStatic] namespace MS.Internal { internal interface IAppDomainShutdownListener { void NotifyShutdown(); } internal static class AppDomainShutdownMonitor { static AppDomainShutdownMonitor() { AppDomain.CurrentDomain.DomainUnload += OnShutdown; AppDomain.CurrentDomain.ProcessExit += OnShutdown; _dictionary = new Dictionary(); } public static void Add(WeakReference listener) { Debug.Assert(listener.Target != null); Debug.Assert(listener.Target is IAppDomainShutdownListener); lock (_dictionary) { if (!_shuttingDown) { _dictionary.Add(listener, listener); } } } public static void Remove(WeakReference listener) { Debug.Assert(listener.Target == null || listener.Target is IAppDomainShutdownListener); lock (_dictionary) { if (!_shuttingDown) { _dictionary.Remove(listener); } } } private static void OnShutdown(object sender, EventArgs e) { lock (_dictionary) { // Setting this to true prevents Add and Remove from modifying the list. This // way we call out without holding a lock (which would be bad) _shuttingDown = true; } foreach (WeakReference value in _dictionary.Values) { IAppDomainShutdownListener listener = value.Target as IAppDomainShutdownListener; if (listener != null) { listener.NotifyShutdown(); } } } private static Dictionary _dictionary; private static bool _shuttingDown; } } // 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
- StorageSetMapping.cs
- XmlElementList.cs
- StrokeFIndices.cs
- FeatureSupport.cs
- GeneratedContractType.cs
- ErrorRuntimeConfig.cs
- PipelineModuleStepContainer.cs
- BuildTopDownAttribute.cs
- SpotLight.cs
- HeaderUtility.cs
- Wildcard.cs
- Decimal.cs
- StrokeSerializer.cs
- Stream.cs
- Sql8ExpressionRewriter.cs
- WebBrowserSiteBase.cs
- Label.cs
- TrustLevelCollection.cs
- ExpressionSelection.cs
- Size.cs
- XmlAttributeAttribute.cs
- TypeElementCollection.cs
- SortAction.cs
- DataGridTextBoxColumn.cs
- Version.cs
- dtdvalidator.cs
- DebugView.cs
- SecureStringHasher.cs
- SqlRetyper.cs
- APCustomTypeDescriptor.cs
- ETagAttribute.cs
- XmlComplianceUtil.cs
- Menu.cs
- WorkflowViewManager.cs
- SqlDependencyListener.cs
- PageParserFilter.cs
- ExtendLockAsyncResult.cs
- OdbcFactory.cs
- IDispatchConstantAttribute.cs
- XmlSerializerAssemblyAttribute.cs
- NullableConverter.cs
- ToolBarButton.cs
- WebHttpSecurityElement.cs
- TreeSet.cs
- MailSettingsSection.cs
- InputScopeManager.cs
- ScriptIgnoreAttribute.cs
- ProfessionalColors.cs
- TypeDescriptor.cs
- PerformanceCounterPermissionAttribute.cs
- UriParserTemplates.cs
- SessionEndingCancelEventArgs.cs
- SendMessageChannelCache.cs
- Size3DValueSerializer.cs
- TCEAdapterGenerator.cs
- WorkflowRuntimeServiceElement.cs
- BrowserCapabilitiesFactoryBase.cs
- SettingsContext.cs
- PageFunction.cs
- DurableInstanceProvider.cs
- CollectionViewGroup.cs
- EventToken.cs
- XmlSchemaComplexContentExtension.cs
- DateTimeUtil.cs
- FieldAccessException.cs
- PartialArray.cs
- AccessKeyManager.cs
- TraceHandlerErrorFormatter.cs
- StructuredTypeInfo.cs
- EntryIndex.cs
- DecimalConstantAttribute.cs
- EnumerableValidator.cs
- EventTrigger.cs
- InputScopeNameConverter.cs
- AppDomainProtocolHandler.cs
- ProviderConnectionPoint.cs
- UserPersonalizationStateInfo.cs
- ScrollViewer.cs
- MimeTypeAttribute.cs
- SafeFileMapViewHandle.cs
- ItemList.cs
- InteropAutomationProvider.cs
- XmlSchemaSimpleType.cs
- XmlBoundElement.cs
- TextFormatterHost.cs
- XmlEntity.cs
- InheritanceRules.cs
- PersonalizableAttribute.cs
- BulletDecorator.cs
- PathFigure.cs
- MediaEntryAttribute.cs
- ControlPropertyNameConverter.cs
- X509CertificateValidationMode.cs
- XslCompiledTransform.cs
- Overlapped.cs
- XPathPatternBuilder.cs
- GenericRootAutomationPeer.cs
- AuthenticateEventArgs.cs
- SqlUtil.cs
- DateTimeStorage.cs