Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / 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. 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
- PathBox.cs
- DateTimeStorage.cs
- DataGridViewCellCancelEventArgs.cs
- QuotaThrottle.cs
- PnrpPermission.cs
- InputScope.cs
- SQLDecimal.cs
- ContentDefinition.cs
- Select.cs
- nulltextcontainer.cs
- ControlParameter.cs
- ClassicBorderDecorator.cs
- NetDispatcherFaultException.cs
- TransformedBitmap.cs
- NullableLongAverageAggregationOperator.cs
- ScriptBehaviorDescriptor.cs
- Journal.cs
- GridPattern.cs
- CssClassPropertyAttribute.cs
- SqlBooleanMismatchVisitor.cs
- AmbientLight.cs
- CustomErrorsSectionWrapper.cs
- ConsumerConnectionPoint.cs
- DiscoveryDocumentSearchPattern.cs
- ClassHandlersStore.cs
- streamingZipPartStream.cs
- ByteStorage.cs
- ResourceContainer.cs
- SiteMapPathDesigner.cs
- DataServiceHostWrapper.cs
- DataListItem.cs
- HotCommands.cs
- ContentOperations.cs
- ClientSponsor.cs
- ServiceMetadataBehavior.cs
- HashLookup.cs
- TraceUtility.cs
- ProfilePropertySettingsCollection.cs
- WindowProviderWrapper.cs
- Html32TextWriter.cs
- TextContainer.cs
- ListView.cs
- KeyInstance.cs
- X509Utils.cs
- IsolatedStoragePermission.cs
- RelationshipType.cs
- CheckoutException.cs
- _ListenerResponseStream.cs
- WebResourceUtil.cs
- LogArchiveSnapshot.cs
- DetailsView.cs
- HttpModulesSection.cs
- RIPEMD160.cs
- SocketPermission.cs
- Attribute.cs
- ProviderConnectionPoint.cs
- Win32NamedPipes.cs
- MessageQueue.cs
- ResizeGrip.cs
- WebPartDescription.cs
- PerformanceCounterPermission.cs
- BindingList.cs
- InternalDispatchObject.cs
- UshortList2.cs
- EntitySetRetriever.cs
- SingleTagSectionHandler.cs
- SynchronizedDisposablePool.cs
- Accessible.cs
- GridViewRowEventArgs.cs
- ScaleTransform3D.cs
- DispatcherExceptionEventArgs.cs
- XmlSchemaAll.cs
- SimpleLine.cs
- ConfigurationHandlersInstallComponent.cs
- SettingsPropertyWrongTypeException.cs
- MsmqElementBase.cs
- GlobalAllocSafeHandle.cs
- ProfileSettings.cs
- Token.cs
- ClientBuildManager.cs
- MetadataCache.cs
- CodeBlockBuilder.cs
- MultipleCopiesCollection.cs
- DbConnectionClosed.cs
- SkipQueryOptionExpression.cs
- NumberFormatInfo.cs
- ParserContext.cs
- XhtmlBasicControlAdapter.cs
- NativeMethods.cs
- RemotingServices.cs
- PostBackOptions.cs
- UriTemplateCompoundPathSegment.cs
- BinaryUtilClasses.cs
- PathTooLongException.cs
- _SslSessionsCache.cs
- XmlSchemaIdentityConstraint.cs
- SqlProviderManifest.cs
- Timeline.cs
- RequestCachingSection.cs
- XmlSignatureManifest.cs