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
- WebPartCollection.cs
- ClickablePoint.cs
- DataSourceView.cs
- FontEmbeddingManager.cs
- DataList.cs
- StylusTip.cs
- UrlMapping.cs
- DbProviderFactories.cs
- Pkcs7Recipient.cs
- EntityViewGenerationAttribute.cs
- UnrecognizedAssertionsBindingElement.cs
- GridViewEditEventArgs.cs
- Section.cs
- StaticExtensionConverter.cs
- HexParser.cs
- DragCompletedEventArgs.cs
- RsaSecurityToken.cs
- DesignerLinkAdapter.cs
- DefaultBindingPropertyAttribute.cs
- PassportPrincipal.cs
- ContextMenu.cs
- ObjectDataSourceView.cs
- WebPartCloseVerb.cs
- DocumentXmlWriter.cs
- NonPrimarySelectionGlyph.cs
- BaseCAMarshaler.cs
- DependencyProperty.cs
- TextSelectionProcessor.cs
- WindowsFormsHelpers.cs
- OrderedDictionaryStateHelper.cs
- Win32.cs
- FixedStringLookup.cs
- ObjectListItem.cs
- FixUpCollection.cs
- ExtensionDataObject.cs
- QilPatternFactory.cs
- OleStrCAMarshaler.cs
- WinInet.cs
- StdValidatorsAndConverters.cs
- ServiceAuthorizationElement.cs
- Comparer.cs
- GifBitmapEncoder.cs
- DesignTimeValidationFeature.cs
- GeometryGroup.cs
- SerialPinChanges.cs
- Int16KeyFrameCollection.cs
- ChildTable.cs
- Serializer.cs
- GroupBoxRenderer.cs
- Style.cs
- SqlClientWrapperSmiStreamChars.cs
- EdmToObjectNamespaceMap.cs
- StringResourceManager.cs
- M3DUtil.cs
- FormViewDeleteEventArgs.cs
- NamespaceInfo.cs
- MsmqHostedTransportManager.cs
- GroupByQueryOperator.cs
- ManagedFilter.cs
- VariantWrapper.cs
- TreeView.cs
- DesignerTransaction.cs
- ImageCodecInfo.cs
- TreeBuilderXamlTranslator.cs
- SchemaName.cs
- ManualResetEvent.cs
- MsmqIntegrationProcessProtocolHandler.cs
- UpdatePanelTrigger.cs
- RowVisual.cs
- SystemColorTracker.cs
- PermissionSet.cs
- BufferedWebEventProvider.cs
- EntityProxyFactory.cs
- WebPartUserCapability.cs
- Literal.cs
- HyperLink.cs
- HyperLink.cs
- PluralizationServiceUtil.cs
- PlanCompiler.cs
- NamespaceCollection.cs
- LambdaCompiler.Binary.cs
- SequenceNumber.cs
- UIElement.cs
- TraceLog.cs
- HealthMonitoringSectionHelper.cs
- ServiceDiscoveryElement.cs
- DesignerActionService.cs
- Latin1Encoding.cs
- QueryResults.cs
- ServiceConfigurationTraceRecord.cs
- Documentation.cs
- FormattedTextSymbols.cs
- DefaultValueAttribute.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- DecoratedNameAttribute.cs
- SqlMethodTransformer.cs
- NameTable.cs
- DataGridViewMethods.cs
- ComponentConverter.cs
- BitmapEffectOutputConnector.cs