Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- InkCanvasAutomationPeer.cs
- TransformGroup.cs
- CallContext.cs
- DirectoryInfo.cs
- DrawingCollection.cs
- SqlDataReaderSmi.cs
- InvariantComparer.cs
- BamlLocalizationDictionary.cs
- RelatedEnd.cs
- MemberCollection.cs
- DBSqlParserTable.cs
- ExpandCollapsePattern.cs
- SettingsPropertyCollection.cs
- SqlMetaData.cs
- LabelInfo.cs
- TypeSource.cs
- SafeCryptHandles.cs
- DateTimeFormat.cs
- ListViewItem.cs
- TextBox.cs
- TimeManager.cs
- XmlSchemaExternal.cs
- DoubleKeyFrameCollection.cs
- RouteItem.cs
- ContractValidationHelper.cs
- UriSchemeKeyedCollection.cs
- TypedTableBase.cs
- ProxyWebPartConnectionCollection.cs
- SoapCommonClasses.cs
- SourceFilter.cs
- SplitterCancelEvent.cs
- PointAnimationUsingKeyFrames.cs
- Funcletizer.cs
- PnrpPermission.cs
- ListViewPagedDataSource.cs
- DerivedKeySecurityToken.cs
- X509DefaultServiceCertificateElement.cs
- Mappings.cs
- IisTraceWebEventProvider.cs
- StylusPointCollection.cs
- SoapWriter.cs
- OdbcFactory.cs
- ButtonFlatAdapter.cs
- _SslSessionsCache.cs
- SHA512CryptoServiceProvider.cs
- ScrollContentPresenter.cs
- XmlSchemaParticle.cs
- PeerCustomResolverSettings.cs
- SiteMembershipCondition.cs
- Ticks.cs
- CellIdBoolean.cs
- EdmScalarPropertyAttribute.cs
- MatrixTransform3D.cs
- HttpResponseInternalWrapper.cs
- ScrollBarRenderer.cs
- ObjectStateEntry.cs
- SafeBitVector32.cs
- RefreshResponseInfo.cs
- ExpiredSecurityTokenException.cs
- SpeechSynthesizer.cs
- HttpCachePolicy.cs
- _OverlappedAsyncResult.cs
- Command.cs
- TargetControlTypeCache.cs
- brushes.cs
- KoreanCalendar.cs
- CFStream.cs
- WebControlToolBoxItem.cs
- WaitHandle.cs
- Themes.cs
- listitem.cs
- Nullable.cs
- ZipIOLocalFileBlock.cs
- PropertyValue.cs
- SqlRowUpdatingEvent.cs
- ListViewItem.cs
- ClientApiGenerator.cs
- FieldToken.cs
- TraversalRequest.cs
- MessageContractImporter.cs
- _ContextAwareResult.cs
- PasswordBoxAutomationPeer.cs
- ThemeDictionaryExtension.cs
- Pair.cs
- WebBrowserPermission.cs
- StrokeRenderer.cs
- CommandEventArgs.cs
- FieldNameLookup.cs
- Resources.Designer.cs
- DataServiceExpressionVisitor.cs
- WebHttpSecurityElement.cs
- FontInfo.cs
- QueryGenerator.cs
- ICollection.cs
- ColorConverter.cs
- QilFactory.cs
- XmlRawWriter.cs
- ThreadStartException.cs
- SqlNodeAnnotations.cs
- ClearCollection.cs