Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Core / System / Windows / EventRouteFactory.cs / 1 / EventRouteFactory.cs
using System;
using System.Windows;
using MS.Utility;
namespace System.Windows
{
///
/// Creates and recycles instance of EventRoute
///
internal static class EventRouteFactory
{
#region Operations
///
/// Fetch a recycled object if available
/// else create a new instance
///
internal static EventRoute FetchObject(RoutedEvent routedEvent)
{
EventRoute eventRoute = Pop();
if (eventRoute == null)
{
eventRoute = new EventRoute(routedEvent);
}
else
{
eventRoute.RoutedEvent = routedEvent;
}
return eventRoute;
}
///
/// Recycle the given instance of EventRoute
///
internal static void RecycleObject(EventRoute eventRoute)
{
// Cleanup all refernces held
eventRoute.Clear();
// Push instance on to the stack
Push(eventRoute);
}
#endregion Operations
#region HelperMethods
///
/// Push the given instance of EventRoute on to the stack
///
private static void Push(EventRoute eventRoute)
{
lock (_synchronized)
{
// In a normal scenario it is extremely rare to
// require more than 2 EventRoutes at the same time
if (_eventRouteStack == null)
{
_eventRouteStack = new EventRoute[2];
_stackTop = 0;
}
if (_stackTop < 2)
{
_eventRouteStack[_stackTop++] = eventRoute;
}
}
}
///
/// Pop off the last instance of EventRoute in the stack
///
private static EventRoute Pop()
{
lock (_synchronized)
{
if (_stackTop > 0)
{
EventRoute eventRoute = _eventRouteStack[--_stackTop];
_eventRouteStack[_stackTop] = null;
return eventRoute;
}
}
return null;
}
#endregion HelperMethods
#region Data
private static EventRoute[] _eventRouteStack;
private static int _stackTop;
private static object _synchronized = new object();
#endregion Data
}
}
// 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
- DatasetMethodGenerator.cs
- ISFTagAndGuidCache.cs
- NameValueFileSectionHandler.cs
- ServiceMemoryGates.cs
- InvalidFilterCriteriaException.cs
- WindowsFormsLinkLabel.cs
- BinaryExpression.cs
- GraphicsState.cs
- LoadGrammarCompletedEventArgs.cs
- ChannelManager.cs
- WorkflowRuntimeEndpoint.cs
- GetWinFXPath.cs
- AddInAttribute.cs
- InputElement.cs
- ResourcesBuildProvider.cs
- WebPartCloseVerb.cs
- Rules.cs
- RawStylusInput.cs
- PointAnimationUsingPath.cs
- ExpressionBindingCollection.cs
- Int32CAMarshaler.cs
- ColorEditor.cs
- X509CertificateCollection.cs
- ColorConverter.cs
- SmtpFailedRecipientsException.cs
- RegionIterator.cs
- Point.cs
- EngineSite.cs
- TableRow.cs
- SQLString.cs
- TypeExtension.cs
- TimeSpanFormat.cs
- WSDualHttpBindingElement.cs
- SqlUtils.cs
- XmlCharacterData.cs
- XmlMemberMapping.cs
- CacheChildrenQuery.cs
- TypeConverterValueSerializer.cs
- IdentityHolder.cs
- StringValidatorAttribute.cs
- ByteStream.cs
- SafePointer.cs
- SpellerError.cs
- FixedSOMImage.cs
- CodeDomLoader.cs
- TextRunProperties.cs
- KeyboardEventArgs.cs
- JoinElimination.cs
- DataGridViewCellPaintingEventArgs.cs
- ChannelServices.cs
- BeginEvent.cs
- ProgramPublisher.cs
- MarkupCompilePass2.cs
- WebPartCatalogAddVerb.cs
- FieldMetadata.cs
- WithStatement.cs
- SimpleExpression.cs
- RetrieveVirtualItemEventArgs.cs
- StateFinalizationActivity.cs
- ResourceDescriptionAttribute.cs
- DiscoveryVersion.cs
- AssemblyNameProxy.cs
- NamespaceQuery.cs
- FigureHelper.cs
- SqlCommand.cs
- VirtualDirectoryMapping.cs
- BuildProvider.cs
- HttpPostClientProtocol.cs
- SynchronizedDispatch.cs
- TagMapCollection.cs
- RequestChannelBinder.cs
- DataRowChangeEvent.cs
- _CacheStreams.cs
- EntryWrittenEventArgs.cs
- BindableTemplateBuilder.cs
- XmlSerializerFormatAttribute.cs
- StateMachineSubscription.cs
- ToolStripRenderer.cs
- SafeIUnknown.cs
- _ListenerResponseStream.cs
- WindowsSpinner.cs
- UnaryNode.cs
- SQLBinary.cs
- RelationshipWrapper.cs
- LineInfo.cs
- EventLogQuery.cs
- SQLGuidStorage.cs
- Shape.cs
- CFGGrammar.cs
- Brush.cs
- CorrelationHandle.cs
- CodeObject.cs
- Number.cs
- OdbcInfoMessageEvent.cs
- LocatorGroup.cs
- HotSpotCollectionEditor.cs
- PassportPrincipal.cs
- PipeStream.cs
- SubtreeProcessor.cs
- ECDsa.cs