Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- Byte.cs
- WinFormsComponentEditor.cs
- ExternalCalls.cs
- RowToParametersTransformer.cs
- SessionEndedEventArgs.cs
- SapiInterop.cs
- SmtpTransport.cs
- IdentityNotMappedException.cs
- Matrix3DStack.cs
- EntryIndex.cs
- WmlImageAdapter.cs
- TimerElapsedEvenArgs.cs
- ConditionalAttribute.cs
- ModelServiceImpl.cs
- AsyncOperation.cs
- SharedHttpsTransportManager.cs
- OdbcEnvironment.cs
- GeometryConverter.cs
- SystemBrushes.cs
- InstanceLockLostException.cs
- DesignSurface.cs
- NullReferenceException.cs
- ReferenceConverter.cs
- CounterCreationData.cs
- BaseResourcesBuildProvider.cs
- AtomContentProperty.cs
- _IPv4Address.cs
- TransactionScope.cs
- Span.cs
- Variant.cs
- RemotingConfigParser.cs
- PolicyChain.cs
- JoinTreeNode.cs
- SqlGenerator.cs
- ComboBox.cs
- DataGridViewSelectedRowCollection.cs
- BulletChrome.cs
- MessagePartDescription.cs
- Image.cs
- MenuItemAutomationPeer.cs
- List.cs
- HttpModulesSection.cs
- OSFeature.cs
- ValueOfAction.cs
- EditingCommands.cs
- ServiceProviders.cs
- ClientOptions.cs
- TimeZone.cs
- BeginCreateSecurityTokenRequest.cs
- KeyProperty.cs
- ToolstripProfessionalRenderer.cs
- DebugView.cs
- RelationshipSet.cs
- FirstMatchCodeGroup.cs
- FlowDecision.cs
- WizardStepBase.cs
- LinkedResourceCollection.cs
- UnsafeNativeMethodsCLR.cs
- ResourceIDHelper.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- KeyValueConfigurationElement.cs
- BindingExpressionUncommonField.cs
- DataGridViewBand.cs
- _UncName.cs
- OleDbCommand.cs
- FutureFactory.cs
- SoapIncludeAttribute.cs
- PropertyManager.cs
- SchemaNames.cs
- FontStyleConverter.cs
- MetadataItem_Static.cs
- ISCIIEncoding.cs
- XmlRawWriter.cs
- HtmlInputControl.cs
- Effect.cs
- _KerberosClient.cs
- WebPermission.cs
- PinnedBufferMemoryStream.cs
- EventLogger.cs
- BooleanExpr.cs
- SystemIPv6InterfaceProperties.cs
- EncoderFallback.cs
- Base64Encoding.cs
- ApplyTemplatesAction.cs
- StringUtil.cs
- CodeTypeOfExpression.cs
- ExpressionNode.cs
- AlternateViewCollection.cs
- SingleTagSectionHandler.cs
- CompositionAdorner.cs
- TrustExchangeException.cs
- TriState.cs
- DataSourceProvider.cs
- DrawingAttributeSerializer.cs
- ByteStreamMessageEncodingElement.cs
- SecurityAlgorithmSuiteConverter.cs
- BinaryMessageEncodingElement.cs
- PtsContext.cs
- PrefixQName.cs
- PrintPreviewDialog.cs