Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Shared / MS / Internal / AppDomainShutdownMonitor.cs / 1305600 / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SerTrace.cs
- HMACSHA384.cs
- DataGridRow.cs
- ColorDialog.cs
- XPathException.cs
- AuthenticationConfig.cs
- TdsParserStaticMethods.cs
- SmtpSection.cs
- ThemeInfoAttribute.cs
- FactoryRecord.cs
- Activation.cs
- TransformGroup.cs
- DatagridviewDisplayedBandsData.cs
- Math.cs
- RequestCacheManager.cs
- EditorPartChrome.cs
- ConstNode.cs
- CheckBox.cs
- HtmlInputButton.cs
- GlyphInfoList.cs
- AnimationClock.cs
- _OSSOCK.cs
- SynchronousChannel.cs
- ProtectedConfigurationSection.cs
- ColorAnimationUsingKeyFrames.cs
- SecurityDescriptor.cs
- InputProviderSite.cs
- DesignTimeType.cs
- Odbc32.cs
- GeometryDrawing.cs
- FormatControl.cs
- TextEditorLists.cs
- CompoundFileReference.cs
- RoleService.cs
- DataViewManagerListItemTypeDescriptor.cs
- PreProcessor.cs
- WindowProviderWrapper.cs
- DataGridViewCellCollection.cs
- BindingListCollectionView.cs
- XmlSortKey.cs
- HybridDictionary.cs
- ParentQuery.cs
- LZCodec.cs
- QilXmlReader.cs
- __ComObject.cs
- SimpleRecyclingCache.cs
- ArgumentOutOfRangeException.cs
- DrawingCollection.cs
- _ScatterGatherBuffers.cs
- BindingOperations.cs
- RenderData.cs
- XmlProcessingInstruction.cs
- UIInitializationException.cs
- SecureStringHasher.cs
- OdbcConnectionPoolProviderInfo.cs
- SiteMapNodeCollection.cs
- BuildProviderCollection.cs
- UnknownBitmapEncoder.cs
- FontFamilyIdentifier.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- ScriptBehaviorDescriptor.cs
- Transform3DCollection.cs
- InvalidAsynchronousStateException.cs
- UnrecognizedPolicyAssertionElement.cs
- DoubleLinkListEnumerator.cs
- BindingValueChangedEventArgs.cs
- sqlcontext.cs
- LowerCaseStringConverter.cs
- BooleanFunctions.cs
- RawAppCommandInputReport.cs
- OleAutBinder.cs
- BaseDataListPage.cs
- TableRowCollection.cs
- RepeatButton.cs
- ConstrainedDataObject.cs
- SQLInt16.cs
- UIElement.cs
- StructuredTypeInfo.cs
- ProtectedConfiguration.cs
- MtomMessageEncodingBindingElement.cs
- ListBoxItem.cs
- OutOfMemoryException.cs
- InvalidAsynchronousStateException.cs
- querybuilder.cs
- ElapsedEventArgs.cs
- XhtmlBasicLiteralTextAdapter.cs
- RelationshipFixer.cs
- XmlFormatWriterGenerator.cs
- OptimalBreakSession.cs
- SimpleFieldTemplateFactory.cs
- OleDbCommandBuilder.cs
- brushes.cs
- DefaultHttpHandler.cs
- MeshGeometry3D.cs
- BitmapFrameDecode.cs
- WebPartConnectionsCancelEventArgs.cs
- TagPrefixCollection.cs
- ViewLoader.cs
- RepeatInfo.cs
- EUCJPEncoding.cs