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
- DPTypeDescriptorContext.cs
- ContractInstanceProvider.cs
- HttpWriter.cs
- FilterEventArgs.cs
- ContentPresenter.cs
- BindingsCollection.cs
- PassportIdentity.cs
- DependencyObject.cs
- MsmqIntegrationInputMessage.cs
- ToolboxComponentsCreatingEventArgs.cs
- FrameworkName.cs
- TargetParameterCountException.cs
- PrintEvent.cs
- VirtualizedItemPattern.cs
- CollectionViewProxy.cs
- JsonFormatGeneratorStatics.cs
- ApplicationServicesHostFactory.cs
- ReferenceConverter.cs
- Options.cs
- HostingPreferredMapPath.cs
- WeakRefEnumerator.cs
- SiteMapDesignerDataSourceView.cs
- ComplexObject.cs
- HttpHandlersSection.cs
- AssemblyCache.cs
- AssertUtility.cs
- UnsafeNativeMethods.cs
- AffineTransform3D.cs
- CorrelationTokenInvalidatedHandler.cs
- RegisteredDisposeScript.cs
- AsyncOperationContext.cs
- ContainerSelectorGlyph.cs
- ThreadPoolTaskScheduler.cs
- DurationConverter.cs
- NegationPusher.cs
- DataGridHeaderBorder.cs
- FillRuleValidation.cs
- EntitySetDataBindingList.cs
- UriParserTemplates.cs
- ActiveXHelper.cs
- Inline.cs
- ValidationRuleCollection.cs
- MonitoringDescriptionAttribute.cs
- IApplicationTrustManager.cs
- TextModifier.cs
- ExecutionEngineException.cs
- TextReader.cs
- StrongTypingException.cs
- HTMLTagNameToTypeMapper.cs
- ServicePointManager.cs
- PreloadedPackages.cs
- CustomAttribute.cs
- CornerRadius.cs
- TextElementEnumerator.cs
- ProfileServiceManager.cs
- ConfigXmlElement.cs
- ClipboardProcessor.cs
- ConfigurationManagerHelper.cs
- CommentGlyph.cs
- HttpFileCollectionBase.cs
- MaskedTextBoxDesigner.cs
- HashSetDebugView.cs
- FormatPage.cs
- XmlComplianceUtil.cs
- Function.cs
- MasterPageParser.cs
- MasterPageCodeDomTreeGenerator.cs
- CorrelationValidator.cs
- FragmentQueryKB.cs
- XsltConvert.cs
- Menu.cs
- IncomingWebResponseContext.cs
- HtmlButton.cs
- HttpFileCollection.cs
- TabletCollection.cs
- TileBrush.cs
- ToolboxDataAttribute.cs
- securestring.cs
- SymLanguageVendor.cs
- SiteMapHierarchicalDataSourceView.cs
- TraceSection.cs
- RawStylusInputCustomDataList.cs
- StringUtil.cs
- StringArrayConverter.cs
- LinkArea.cs
- RelationshipEndMember.cs
- DataGridTablesFactory.cs
- CalendarTable.cs
- EntityDesignerDataSourceView.cs
- DataGridViewRowCollection.cs
- EntityDataSourceDataSelectionPanel.cs
- NetStream.cs
- _BasicClient.cs
- Emitter.cs
- ACL.cs
- ContainerCodeDomSerializer.cs
- Version.cs
- FormsAuthenticationEventArgs.cs
- ClientApiGenerator.cs
- ResolveNameEventArgs.cs