Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / EventRouteFactory.cs / 1305600 / 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
- AnnotationElement.cs
- ListControlBoundActionList.cs
- RuleSetBrowserDialog.cs
- FaultDescriptionCollection.cs
- PathSegment.cs
- PipeConnection.cs
- BindingMAnagerBase.cs
- AssociationSetEnd.cs
- GestureRecognitionResult.cs
- MouseBinding.cs
- SHA512.cs
- BinHexDecoder.cs
- ShaderRenderModeValidation.cs
- DataSourceControlBuilder.cs
- SettingsAttributeDictionary.cs
- EnumerableRowCollection.cs
- ScalarConstant.cs
- ExpressionBindings.cs
- Parameter.cs
- Input.cs
- ImageSource.cs
- ComponentRenameEvent.cs
- TextBoxLine.cs
- DbMetaDataCollectionNames.cs
- BamlTreeNode.cs
- JulianCalendar.cs
- NamedPipeConnectionPool.cs
- DefaultTraceListener.cs
- XmlArrayItemAttribute.cs
- SpotLight.cs
- ContentTextAutomationPeer.cs
- Floater.cs
- SchemaTableOptionalColumn.cs
- NameScope.cs
- MimeReflector.cs
- ConfigurationValidatorBase.cs
- XmlNodeChangedEventManager.cs
- ColorPalette.cs
- DaylightTime.cs
- TabletCollection.cs
- StylusEventArgs.cs
- StorageEndPropertyMapping.cs
- DockAndAnchorLayout.cs
- ResolveResponse.cs
- ProcessHostConfigUtils.cs
- FontSizeConverter.cs
- odbcmetadatacolumnnames.cs
- HtmlLink.cs
- SchemaImporter.cs
- HttpModuleAction.cs
- MenuItemBindingCollection.cs
- EntityDataSourceContainerNameItem.cs
- PixelFormats.cs
- ByteConverter.cs
- ElementHostAutomationPeer.cs
- DefaultAutoFieldGenerator.cs
- DataGridViewRowEventArgs.cs
- DesignerCommandSet.cs
- ChtmlTextBoxAdapter.cs
- XDRSchema.cs
- WebMessageEncoderFactory.cs
- InvokeBase.cs
- storepermission.cs
- __Error.cs
- DNS.cs
- x509utils.cs
- ImageSource.cs
- NamespaceTable.cs
- RedBlackList.cs
- ScriptingSectionGroup.cs
- RunClient.cs
- DataSpaceManager.cs
- TwoPhaseCommitProxy.cs
- ScrollEvent.cs
- RNGCryptoServiceProvider.cs
- QueryOperator.cs
- CodeDefaultValueExpression.cs
- TdsValueSetter.cs
- ValidationSummary.cs
- DefaultProxySection.cs
- XPathArrayIterator.cs
- Thickness.cs
- KnownAssembliesSet.cs
- CollectionBuilder.cs
- DataSourceExpressionCollection.cs
- HtmlFormParameterWriter.cs
- SqlFactory.cs
- VisualStateManager.cs
- ToolZoneDesigner.cs
- XmlSchemaComplexType.cs
- RelationshipConstraintValidator.cs
- DescendantBaseQuery.cs
- FontDifferentiator.cs
- MapPathBasedVirtualPathProvider.cs
- RawUIStateInputReport.cs
- DataGridViewCellCollection.cs
- COM2ExtendedBrowsingHandler.cs
- XmlCharCheckingWriter.cs
- SequentialUshortCollection.cs
- WebPartExportVerb.cs