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
- CommandID.cs
- PeerApplicationLaunchInfo.cs
- SymmetricSecurityProtocolFactory.cs
- HttpModuleActionCollection.cs
- GridViewRowEventArgs.cs
- OutputCacheProfile.cs
- ResourcesBuildProvider.cs
- ApplicationManager.cs
- RemotingConfiguration.cs
- CertificateElement.cs
- DataSvcMapFile.cs
- LookupNode.cs
- ExclusiveTcpListener.cs
- HttpModuleActionCollection.cs
- ObfuscationAttribute.cs
- hwndwrapper.cs
- QilName.cs
- DataGridParentRows.cs
- CapabilitiesPattern.cs
- HierarchicalDataSourceIDConverter.cs
- AstTree.cs
- ArglessEventHandlerProxy.cs
- ObjectDataSourceSelectingEventArgs.cs
- UIAgentAsyncEndRequest.cs
- MembershipSection.cs
- StructuredType.cs
- ConnectionStringSettings.cs
- TCPListener.cs
- ParameterModifier.cs
- FilterFactory.cs
- DiscardableAttribute.cs
- WebPartVerbsEventArgs.cs
- QilStrConcatenator.cs
- ReadOnlyPropertyMetadata.cs
- SerializationInfo.cs
- TreeNodeStyle.cs
- GridViewSortEventArgs.cs
- BitmapSizeOptions.cs
- BooleanProjectedSlot.cs
- TextEditorDragDrop.cs
- XmlSchemaSimpleContentRestriction.cs
- MobileCapabilities.cs
- ValidationError.cs
- RelationshipWrapper.cs
- ReflectionUtil.cs
- CodeArgumentReferenceExpression.cs
- Matrix3D.cs
- TypeReference.cs
- ListenerElementsCollection.cs
- SqlNodeTypeOperators.cs
- AudioFormatConverter.cs
- WizardPanelChangingEventArgs.cs
- ContextBase.cs
- ControlIdConverter.cs
- ToolboxComponentsCreatingEventArgs.cs
- TreeNodeCollectionEditor.cs
- SystemEvents.cs
- X509ScopedServiceCertificateElementCollection.cs
- ReceiveDesigner.xaml.cs
- ObjectDisposedException.cs
- RoleManagerSection.cs
- BigInt.cs
- Screen.cs
- ComponentCollection.cs
- SqlNotificationEventArgs.cs
- PropertyChangeTracker.cs
- Point3DAnimation.cs
- ConsoleTraceListener.cs
- SoapInteropTypes.cs
- SignedXmlDebugLog.cs
- Win32Native.cs
- WebSysDefaultValueAttribute.cs
- PassportIdentity.cs
- CriticalExceptions.cs
- XmlValidatingReader.cs
- IDispatchConstantAttribute.cs
- ContentTextAutomationPeer.cs
- SystemIPv6InterfaceProperties.cs
- DateTimeHelper.cs
- AnnotationComponentManager.cs
- processwaithandle.cs
- TableCellCollection.cs
- ServiceNameElement.cs
- Assert.cs
- IsolatedStoragePermission.cs
- StorageConditionPropertyMapping.cs
- JoinSymbol.cs
- DoWorkEventArgs.cs
- DiffuseMaterial.cs
- DataReaderContainer.cs
- XmlWhitespace.cs
- HtmlHistory.cs
- SerializationInfoEnumerator.cs
- AttachedPropertyInfo.cs
- ByteStream.cs
- Point4D.cs
- BaseInfoTable.cs
- UICuesEvent.cs
- TextRange.cs
- BoundField.cs