Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- FontEditor.cs
- TextBox.cs
- EntitySqlException.cs
- OleDbRowUpdatingEvent.cs
- ScriptingScriptResourceHandlerSection.cs
- ValueOfAction.cs
- Int64Storage.cs
- XpsS0ValidatingLoader.cs
- SettingsContext.cs
- ShortcutKeysEditor.cs
- EventMap.cs
- OrderedDictionary.cs
- RegexCompilationInfo.cs
- TemplatePagerField.cs
- MimeTextImporter.cs
- IBuiltInEvidence.cs
- _PooledStream.cs
- DelegatingTypeDescriptionProvider.cs
- IISMapPath.cs
- SkinBuilder.cs
- SystemUnicastIPAddressInformation.cs
- AssemblyBuilderData.cs
- HttpModuleAction.cs
- Semaphore.cs
- Light.cs
- ExpressionBuilderContext.cs
- Range.cs
- SubordinateTransaction.cs
- _ListenerRequestStream.cs
- ReadOnlyMetadataCollection.cs
- Executor.cs
- StorageRoot.cs
- SafeEventLogWriteHandle.cs
- SimpleWebHandlerParser.cs
- FixedSOMPageElement.cs
- InstanceLockQueryResult.cs
- EntityTransaction.cs
- XmlSchemaAppInfo.cs
- AppDomainProtocolHandler.cs
- DiffuseMaterial.cs
- CodeTypeParameterCollection.cs
- SafeSystemMetrics.cs
- UnsafeNativeMethods.cs
- ResourceProviderFactory.cs
- BinHexEncoder.cs
- TraceEventCache.cs
- TableMethodGenerator.cs
- RequestCachePolicy.cs
- Single.cs
- DateTimePicker.cs
- PenContexts.cs
- XmlSchemaChoice.cs
- Random.cs
- TableLayoutRowStyleCollection.cs
- NestedContainer.cs
- ThreadSafeList.cs
- LongValidator.cs
- TextEmbeddedObject.cs
- XmlComment.cs
- SqlCommandBuilder.cs
- StateChangeEvent.cs
- QuaternionAnimation.cs
- DrawingGroupDrawingContext.cs
- odbcmetadatacolumnnames.cs
- Hashtable.cs
- ContractBase.cs
- SqlGatherProducedAliases.cs
- EntitySetRetriever.cs
- ObjectItemAssemblyLoader.cs
- LambdaCompiler.Unary.cs
- RenderCapability.cs
- InProcStateClientManager.cs
- WsatProxy.cs
- Message.cs
- DtrList.cs
- ResourcesChangeInfo.cs
- UIElementHelper.cs
- StorageEntityContainerMapping.cs
- _StreamFramer.cs
- ListViewUpdatedEventArgs.cs
- Shape.cs
- GenericAuthenticationEventArgs.cs
- Filter.cs
- DocumentViewerAutomationPeer.cs
- XmlNullResolver.cs
- DelegatedStream.cs
- RoleService.cs
- FacetChecker.cs
- SelectingProviderEventArgs.cs
- TransformPattern.cs
- CodeDomDesignerLoader.cs
- OpenFileDialog.cs
- StylusPointProperty.cs
- X509CertificateInitiatorClientCredential.cs
- InstanceStoreQueryResult.cs
- FSWPathEditor.cs
- ValueExpressions.cs
- LicenseProviderAttribute.cs
- RectAnimationClockResource.cs
- XmlSchemaComplexContentExtension.cs