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
- PatternMatcher.cs
- SafeCryptoKeyHandle.cs
- FontFamily.cs
- EntityDataSourceUtil.cs
- ProtocolsSection.cs
- WCFModelStrings.Designer.cs
- QuadTree.cs
- DesignerToolStripControlHost.cs
- HelpExampleGenerator.cs
- SevenBitStream.cs
- Rect.cs
- DataSourceCacheDurationConverter.cs
- HttpFileCollection.cs
- InvalidEnumArgumentException.cs
- DataGridPageChangedEventArgs.cs
- InstanceCompleteException.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- WebPartHelpVerb.cs
- CacheDependency.cs
- ConditionalAttribute.cs
- Event.cs
- ChtmlCalendarAdapter.cs
- QilFunction.cs
- ClearTypeHintValidation.cs
- httpapplicationstate.cs
- SqlUDTStorage.cs
- WebControlsSection.cs
- DefaultBindingPropertyAttribute.cs
- ResourceProviderFactory.cs
- RightsManagementPermission.cs
- COM2ICategorizePropertiesHandler.cs
- Pool.cs
- TrackingMemoryStream.cs
- ComContractElementCollection.cs
- ConsoleKeyInfo.cs
- SerializeAbsoluteContext.cs
- SqlNodeAnnotation.cs
- RijndaelManaged.cs
- WebPartCloseVerb.cs
- DirectoryLocalQuery.cs
- LazyTextWriterCreator.cs
- SourceItem.cs
- SemanticResolver.cs
- FromRequest.cs
- AutoSizeComboBox.cs
- WindowAutomationPeer.cs
- DataServiceRequestArgs.cs
- DataGridLength.cs
- RawTextInputReport.cs
- GlobalProxySelection.cs
- Html32TextWriter.cs
- GlyphElement.cs
- TaiwanCalendar.cs
- ClassHandlersStore.cs
- ToolBarOverflowPanel.cs
- ExclusiveNamedPipeTransportManager.cs
- RowTypeElement.cs
- ExtensibleClassFactory.cs
- GeneralTransform3DTo2DTo3D.cs
- ELinqQueryState.cs
- ContentElementAutomationPeer.cs
- SupportsPreviewControlAttribute.cs
- WithStatement.cs
- AsymmetricCryptoHandle.cs
- OutputCacheModule.cs
- listitem.cs
- IsolatedStoragePermission.cs
- NullRuntimeConfig.cs
- ReadOnlyHierarchicalDataSource.cs
- PackagingUtilities.cs
- TraceInternal.cs
- DrawingGroup.cs
- WpfWebRequestHelper.cs
- ISFClipboardData.cs
- Walker.cs
- FlowDocument.cs
- WizardPanel.cs
- Vector.cs
- DataGridViewTopLeftHeaderCell.cs
- SoapFormatter.cs
- StateMachine.cs
- ApplicationTrust.cs
- SQLDateTimeStorage.cs
- DataGridToolTip.cs
- OciEnlistContext.cs
- SQLInt64Storage.cs
- CommentEmitter.cs
- CheckBox.cs
- DynamicRenderer.cs
- LogManagementAsyncResult.cs
- ProjectedSlot.cs
- LookupBindingPropertiesAttribute.cs
- ContainerParaClient.cs
- HtmlEmptyTagControlBuilder.cs
- BackgroundWorker.cs
- XsdDuration.cs
- SqlDataReader.cs
- ZipPackage.cs
- SecurityTokenException.cs
- MimeObjectFactory.cs