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
- StateManagedCollection.cs
- ParagraphVisual.cs
- UrlAuthorizationModule.cs
- CheckedPointers.cs
- StreamInfo.cs
- UnauthorizedAccessException.cs
- RoutedUICommand.cs
- FileSecurity.cs
- XsdBuilder.cs
- DbCommandDefinition.cs
- DaylightTime.cs
- EmbeddedMailObject.cs
- RMPublishingDialog.cs
- DbMetaDataFactory.cs
- RegistrationProxy.cs
- IntellisenseTextBox.designer.cs
- XmlCollation.cs
- DataSourceConverter.cs
- StylesEditorDialog.cs
- FigureParagraph.cs
- HttpException.cs
- MatrixTransform.cs
- DateTimeOffsetConverter.cs
- Helpers.cs
- IODescriptionAttribute.cs
- ColumnMapCopier.cs
- TracedNativeMethods.cs
- SortedDictionary.cs
- ComPlusServiceLoader.cs
- SequenceDesignerAccessibleObject.cs
- ImageDrawing.cs
- Thumb.cs
- EntityDataSourceValidationException.cs
- ParseNumbers.cs
- ListViewInsertionMark.cs
- ActivitySurrogateSelector.cs
- DataSourceSerializationException.cs
- ExpressionParser.cs
- XPathQilFactory.cs
- EndOfStreamException.cs
- HttpGetProtocolImporter.cs
- ConsumerConnectionPointCollection.cs
- BidOverLoads.cs
- XmlDataSourceView.cs
- ControlParser.cs
- TextRangeEditLists.cs
- TraceSection.cs
- IISUnsafeMethods.cs
- Missing.cs
- CheckBox.cs
- UiaCoreTypesApi.cs
- ServiceDescriptionContext.cs
- DataGridViewIntLinkedList.cs
- NumericUpDownAcceleration.cs
- ToolbarAUtomationPeer.cs
- GlyphsSerializer.cs
- DesignSurfaceEvent.cs
- ComplexBindingPropertiesAttribute.cs
- DragSelectionMessageFilter.cs
- MoveSizeWinEventHandler.cs
- ValueOfAction.cs
- RemoteWebConfigurationHost.cs
- RangeContentEnumerator.cs
- documentsequencetextview.cs
- AnnotationComponentManager.cs
- BasicHttpSecurityElement.cs
- DoubleConverter.cs
- RuntimeHandles.cs
- XPathNavigatorKeyComparer.cs
- XsltConvert.cs
- PassportPrincipal.cs
- LinkedList.cs
- ContentPropertyAttribute.cs
- TreeViewHitTestInfo.cs
- LayoutInformation.cs
- SatelliteContractVersionAttribute.cs
- NotEqual.cs
- RTTrackingProfile.cs
- CategoryEditor.cs
- BehaviorEditorPart.cs
- EventDescriptorCollection.cs
- SyndicationSerializer.cs
- MsmqInputSessionChannelListener.cs
- _DomainName.cs
- DiagnosticsConfiguration.cs
- SwitchLevelAttribute.cs
- CodeCompiler.cs
- WmlControlAdapter.cs
- WriteFileContext.cs
- ReliabilityContractAttribute.cs
- StructuredTypeEmitter.cs
- SafePipeHandle.cs
- TransformCollection.cs
- CodeChecksumPragma.cs
- IndexExpression.cs
- MouseActionConverter.cs
- CodeLinePragma.cs
- WindowProviderWrapper.cs
- HandoffBehavior.cs
- ASCIIEncoding.cs