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
- SimpleWebHandlerParser.cs
- PingReply.cs
- WebBrowserEvent.cs
- SqlException.cs
- WindowInteropHelper.cs
- InvalidComObjectException.cs
- UIPropertyMetadata.cs
- ProjectionPathSegment.cs
- HMACSHA512.cs
- QueryContinueDragEventArgs.cs
- Task.cs
- StoreItemCollection.cs
- HtmlLiteralTextAdapter.cs
- EventLevel.cs
- ExtentJoinTreeNode.cs
- XsdDuration.cs
- SafeHandles.cs
- COM2IPerPropertyBrowsingHandler.cs
- HashCodeCombiner.cs
- CompositionDesigner.cs
- PaperSize.cs
- Expression.cs
- FunctionImportMapping.ReturnTypeRenameMapping.cs
- InputScopeConverter.cs
- ElementAtQueryOperator.cs
- GradientBrush.cs
- DBCSCodePageEncoding.cs
- SqlBuffer.cs
- HTMLTagNameToTypeMapper.cs
- ImageSourceConverter.cs
- PositiveTimeSpanValidatorAttribute.cs
- PlainXmlWriter.cs
- HttpFileCollection.cs
- CompositeScriptReferenceEventArgs.cs
- RotateTransform.cs
- CodeAttributeDeclarationCollection.cs
- InkCanvasSelection.cs
- CurrentTimeZone.cs
- OleDbPropertySetGuid.cs
- ACE.cs
- AncestorChangedEventArgs.cs
- SplayTreeNode.cs
- Span.cs
- rsa.cs
- MembershipSection.cs
- WsatServiceCertificate.cs
- BitmapPalettes.cs
- DrawingState.cs
- SortedList.cs
- PageParserFilter.cs
- RectConverter.cs
- TimersDescriptionAttribute.cs
- MediaPlayerState.cs
- ControlCollection.cs
- TickBar.cs
- SelectedDatesCollection.cs
- MexHttpsBindingCollectionElement.cs
- SmiRequestExecutor.cs
- CompositeScriptReferenceEventArgs.cs
- ListViewSelectEventArgs.cs
- StyleCollection.cs
- MultipartIdentifier.cs
- ManagementBaseObject.cs
- ReversePositionQuery.cs
- Duration.cs
- Polyline.cs
- DataServiceQueryProvider.cs
- ExpressionBuilderCollection.cs
- RawStylusInputReport.cs
- WindowsListViewGroup.cs
- DeferredSelectedIndexReference.cs
- HostingPreferredMapPath.cs
- DateTimeValueSerializer.cs
- AsyncResult.cs
- CryptoApi.cs
- MarkupCompilePass2.cs
- HostingEnvironmentSection.cs
- ParameterSubsegment.cs
- NativeMethods.cs
- CollectionChange.cs
- UnknownBitmapDecoder.cs
- LabelDesigner.cs
- Clause.cs
- PageParserFilter.cs
- OutputScope.cs
- StylusEventArgs.cs
- CompositeScriptReferenceEventArgs.cs
- PtsHost.cs
- EventHandlersStore.cs
- SynchronizedPool.cs
- HashHelper.cs
- WebRequestModuleElement.cs
- ReaderWriterLock.cs
- MultipartIdentifier.cs
- SchemaEntity.cs
- ComponentConverter.cs
- _CookieModule.cs
- ContextMenuAutomationPeer.cs
- Comparer.cs
- CodeLinePragma.cs