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
- DataControlPagerLinkButton.cs
- GeneralTransformCollection.cs
- DataShape.cs
- ScrollChrome.cs
- ResolveDuplexAsyncResult.cs
- RenderingEventArgs.cs
- MemberAssignmentAnalysis.cs
- TemplateGroupCollection.cs
- ApplySecurityAndSendAsyncResult.cs
- AddToCollection.cs
- EventLogSession.cs
- CellTreeNode.cs
- FileNotFoundException.cs
- XmlSchemaComplexContent.cs
- Point4DValueSerializer.cs
- CfgArc.cs
- SerializationSectionGroup.cs
- InputLanguageProfileNotifySink.cs
- EntityProviderServices.cs
- Camera.cs
- BitmapEffectInput.cs
- Shape.cs
- DataControlImageButton.cs
- BaseTemplateParser.cs
- OdbcCommand.cs
- StyleCollection.cs
- QilXmlReader.cs
- MouseActionConverter.cs
- StaticSiteMapProvider.cs
- SymbolResolver.cs
- AdapterUtil.cs
- CachedPathData.cs
- Util.cs
- NameValueFileSectionHandler.cs
- CorePropertiesFilter.cs
- SoapSchemaImporter.cs
- SafeArrayRankMismatchException.cs
- TableLayoutSettingsTypeConverter.cs
- OleDbWrapper.cs
- BaseAddressElementCollection.cs
- MethodRental.cs
- HtmlTitle.cs
- WindowsImpersonationContext.cs
- ModelVisual3D.cs
- PropertyDescriptors.cs
- PropertyTabAttribute.cs
- SingleAnimationUsingKeyFrames.cs
- Hash.cs
- Bezier.cs
- ObjectReferenceStack.cs
- BadImageFormatException.cs
- ColumnHeaderConverter.cs
- PrintController.cs
- FormatterConverter.cs
- ApplicationServiceManager.cs
- WebEventCodes.cs
- RequestCacheValidator.cs
- CodeDirectoryCompiler.cs
- FixedTextPointer.cs
- TypeBuilderInstantiation.cs
- ControlPropertyNameConverter.cs
- RecognizedPhrase.cs
- MenuAdapter.cs
- ViewStateModeByIdAttribute.cs
- ActiveDocumentEvent.cs
- HttpPostProtocolImporter.cs
- ResourceDescriptionAttribute.cs
- XPathNodePointer.cs
- MaskDescriptor.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- TemplateParser.cs
- ColumnMap.cs
- SByte.cs
- CodeDOMUtility.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- WorkflowServiceHostFactory.cs
- SourceLineInfo.cs
- BitmapSourceSafeMILHandle.cs
- SecurityDescriptor.cs
- EventSinkHelperWriter.cs
- PageContent.cs
- documentsequencetextcontainer.cs
- LayoutUtils.cs
- BitFlagsGenerator.cs
- MainMenu.cs
- SessionStateUtil.cs
- ZipIOFileItemStream.cs
- GeneralTransform3DGroup.cs
- ToolStripSplitStackLayout.cs
- Zone.cs
- DataPagerCommandEventArgs.cs
- UrlAuthorizationModule.cs
- contentDescriptor.cs
- DispatcherHookEventArgs.cs
- DiscriminatorMap.cs
- DESCryptoServiceProvider.cs
- HierarchicalDataSourceControl.cs
- InstanceCreationEditor.cs
- TimelineClockCollection.cs
- DictionaryEntry.cs