Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- QilInvokeLateBound.cs
- RangeBase.cs
- ClickablePoint.cs
- GPStream.cs
- translator.cs
- ResolvePPIDRequest.cs
- MimeTypeAttribute.cs
- GifBitmapDecoder.cs
- ClrPerspective.cs
- HttpException.cs
- BuilderPropertyEntry.cs
- ToolBar.cs
- ProfileInfo.cs
- ThreadExceptionEvent.cs
- TypeExtensions.cs
- EntityContainerEmitter.cs
- StylusPointPropertyUnit.cs
- InteropDesigner.xaml.cs
- FloaterBaseParagraph.cs
- Stack.cs
- XmlQuerySequence.cs
- RegexTree.cs
- NameNode.cs
- ConnectionInterfaceCollection.cs
- ItemDragEvent.cs
- streamingZipPartStream.cs
- InputLangChangeRequestEvent.cs
- WindowsEditBoxRange.cs
- DataSpaceManager.cs
- AxHost.cs
- HttpListenerPrefixCollection.cs
- SelectionItemPatternIdentifiers.cs
- _LocalDataStore.cs
- ResourceProviderFactory.cs
- HelloOperation11AsyncResult.cs
- Subtree.cs
- ParameterToken.cs
- CFStream.cs
- MarkerProperties.cs
- ZipIOBlockManager.cs
- DllNotFoundException.cs
- DialogDivider.cs
- XmlSchemaExternal.cs
- HitTestParameters.cs
- Configuration.cs
- HttpRequestCacheValidator.cs
- BrowserCapabilitiesCodeGenerator.cs
- SqlDataSourceView.cs
- Rotation3D.cs
- BuildProviderInstallComponent.cs
- SqlBuilder.cs
- HMACRIPEMD160.cs
- IncrementalHitTester.cs
- AutomationElementCollection.cs
- UnsafeNetInfoNativeMethods.cs
- BuildTopDownAttribute.cs
- PriorityQueue.cs
- UserControl.cs
- CuspData.cs
- HttpListenerElement.cs
- DataServiceProcessingPipeline.cs
- AppSettingsSection.cs
- PeerChannelListener.cs
- SqlFacetAttribute.cs
- DetailsViewCommandEventArgs.cs
- InternalBufferManager.cs
- WsatRegistrationHeader.cs
- Rotation3DAnimationUsingKeyFrames.cs
- ParentUndoUnit.cs
- BlurEffect.cs
- TextAction.cs
- ToolTipService.cs
- RepeatButtonAutomationPeer.cs
- NativeActivityTransactionContext.cs
- HttpCookiesSection.cs
- TypeSemantics.cs
- UnmanagedBitmapWrapper.cs
- TreeViewCancelEvent.cs
- ConstantCheck.cs
- VectorCollectionConverter.cs
- RegexBoyerMoore.cs
- InvariantComparer.cs
- ImportedPolicyConversionContext.cs
- DataGridViewCellParsingEventArgs.cs
- JoinElimination.cs
- HwndMouseInputProvider.cs
- TraceLevelStore.cs
- PropertyMap.cs
- NamedServiceModelExtensionCollectionElement.cs
- SafeArrayRankMismatchException.cs
- SqlCommand.cs
- ImageAttributes.cs
- VirtualDirectoryMapping.cs
- ArgumentNullException.cs
- VideoDrawing.cs
- DataGridViewCellValidatingEventArgs.cs
- StatusBarItem.cs
- IERequestCache.cs
- ServiceTimeoutsBehavior.cs
- returneventsaver.cs