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
- EntityDataSourceMemberPath.cs
- DurationConverter.cs
- Token.cs
- _HeaderInfoTable.cs
- ValidationPropertyAttribute.cs
- WindowInteropHelper.cs
- GestureRecognizer.cs
- MutexSecurity.cs
- UrlPath.cs
- SimpleWorkerRequest.cs
- ExpressionBuilder.cs
- DrawToolTipEventArgs.cs
- SimpleLine.cs
- SystemPens.cs
- UdpAnnouncementEndpoint.cs
- SpecialNameAttribute.cs
- SerializationObjectManager.cs
- SpotLight.cs
- CollectionContainer.cs
- TreeNode.cs
- BaseCollection.cs
- ChannelReliableSession.cs
- TextTreeExtractElementUndoUnit.cs
- SupportingTokenSpecification.cs
- Grant.cs
- DocumentPaginator.cs
- MaterialGroup.cs
- TripleDESCryptoServiceProvider.cs
- FileDataSourceCache.cs
- XMLSyntaxException.cs
- NamespaceInfo.cs
- XmlAttribute.cs
- RoleExceptions.cs
- PreApplicationStartMethodAttribute.cs
- autovalidator.cs
- HttpApplication.cs
- DbProviderFactoriesConfigurationHandler.cs
- HtmlTableCell.cs
- UriTemplateVariableQueryValue.cs
- CachedFontFamily.cs
- ComNativeDescriptor.cs
- VisualTreeHelper.cs
- GeometryDrawing.cs
- InputScopeConverter.cs
- HtmlContainerControl.cs
- DrawItemEvent.cs
- BamlTreeUpdater.cs
- DbConnectionFactory.cs
- UpdateTracker.cs
- RuleInfoComparer.cs
- DirectoryObjectSecurity.cs
- HttpApplication.cs
- SafeLocalMemHandle.cs
- RoutedPropertyChangedEventArgs.cs
- ConfigurationSectionGroupCollection.cs
- Documentation.cs
- TableItemProviderWrapper.cs
- ServiceModelSectionGroup.cs
- ReplacementText.cs
- StaticSiteMapProvider.cs
- SimpleHandlerFactory.cs
- FrameworkContentElement.cs
- COM2ICategorizePropertiesHandler.cs
- AmbientLight.cs
- Empty.cs
- ParserHooks.cs
- PageContentAsyncResult.cs
- TextFormattingConverter.cs
- CurrencyWrapper.cs
- CategoryGridEntry.cs
- ValueQuery.cs
- ResXResourceSet.cs
- PolyBezierSegment.cs
- QueryProcessor.cs
- MediaContextNotificationWindow.cs
- ContentDesigner.cs
- GridViewPageEventArgs.cs
- CheckBoxStandardAdapter.cs
- CurrentChangingEventManager.cs
- TableCell.cs
- EntityDataSourceWrapperCollection.cs
- OledbConnectionStringbuilder.cs
- DetectRunnableInstancesTask.cs
- RuleCache.cs
- FrameworkElementFactoryMarkupObject.cs
- RectangleHotSpot.cs
- Facet.cs
- RSAPKCS1SignatureFormatter.cs
- LicenseManager.cs
- X509AsymmetricSecurityKey.cs
- EntityUtil.cs
- Decoder.cs
- Membership.cs
- SecurityContext.cs
- DecimalConstantAttribute.cs
- Permission.cs
- Path.cs
- TableDetailsRow.cs
- ConnectionStringsExpressionBuilder.cs
- Line.cs