Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- CounterCreationDataConverter.cs
- DetailsViewInsertEventArgs.cs
- ToolboxComponentsCreatedEventArgs.cs
- SizeF.cs
- TableDesigner.cs
- RegisteredExpandoAttribute.cs
- ReadOnlyDataSourceView.cs
- AutoResizedEvent.cs
- ResourceDefaultValueAttribute.cs
- BinaryFormatter.cs
- AsyncPostBackTrigger.cs
- MouseButton.cs
- XmlUTF8TextReader.cs
- Geometry3D.cs
- OciHandle.cs
- XmlSignatureProperties.cs
- InfoCardAsymmetricCrypto.cs
- RangeBaseAutomationPeer.cs
- LinkedDataMemberFieldEditor.cs
- BindMarkupExtensionSerializer.cs
- DataGridViewBindingCompleteEventArgs.cs
- BuildProvider.cs
- Model3DGroup.cs
- SqlDataSourceQueryConverter.cs
- TableRowCollection.cs
- SpellerError.cs
- XmlSchemaObjectTable.cs
- File.cs
- TraceFilter.cs
- HostProtectionPermission.cs
- SmiMetaDataProperty.cs
- SiteMapDataSource.cs
- FrameworkElementAutomationPeer.cs
- PersonalizationStateInfoCollection.cs
- EdmComplexPropertyAttribute.cs
- ExpressionBindingCollection.cs
- CalendarBlackoutDatesCollection.cs
- TextFindEngine.cs
- SafeBitVector32.cs
- _SSPISessionCache.cs
- TypeListConverter.cs
- ToolZone.cs
- PersonalizationDictionary.cs
- DataRelationPropertyDescriptor.cs
- AudioFormatConverter.cs
- StorageEndPropertyMapping.cs
- ContentFilePart.cs
- ColumnResizeAdorner.cs
- XmlC14NWriter.cs
- GenerateTemporaryTargetAssembly.cs
- EntityType.cs
- TimeSpanConverter.cs
- ValidatingPropertiesEventArgs.cs
- FileLogRecord.cs
- SiteMapNodeItemEventArgs.cs
- ObjectSecurity.cs
- InternalCache.cs
- ResourceContainerWrapper.cs
- AttributeUsageAttribute.cs
- PageThemeParser.cs
- StandardCommands.cs
- AnimationLayer.cs
- DetailsViewRow.cs
- DesignOnlyAttribute.cs
- BrowserCapabilitiesFactory.cs
- AssemblyInfo.cs
- DocumentXPathNavigator.cs
- ConfigurationManager.cs
- DataGridViewDataErrorEventArgs.cs
- AssociationSetEnd.cs
- HtmlInputFile.cs
- ServiceDescriptionReflector.cs
- AuthenticationModuleElement.cs
- DetailsViewRow.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- XmlNotation.cs
- WebControlsSection.cs
- RootBrowserWindow.cs
- PersonalizationState.cs
- RouteData.cs
- OrderByQueryOptionExpression.cs
- SiteIdentityPermission.cs
- UpdatePanelTriggerCollection.cs
- VideoDrawing.cs
- RotateTransform3D.cs
- ViewCellSlot.cs
- SizeAnimationUsingKeyFrames.cs
- safemediahandle.cs
- WebExceptionStatus.cs
- SharedStatics.cs
- OutputCacheEntry.cs
- Rotation3DAnimationBase.cs
- DifferencingCollection.cs
- DefaultObjectSerializer.cs
- PrivilegeNotHeldException.cs
- BookmarkEventArgs.cs
- Int16KeyFrameCollection.cs
- FixedSOMPageConstructor.cs
- SqlDataSourceCommandEventArgs.cs
- SettingsProperty.cs