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
- QuaternionConverter.cs
- XmlHierarchicalDataSourceView.cs
- GeometryDrawing.cs
- DocumentGridContextMenu.cs
- DesignerRegionMouseEventArgs.cs
- DataGridViewSelectedCellCollection.cs
- SiteMapPathDesigner.cs
- SamlAuthorizationDecisionClaimResource.cs
- UserPreferenceChangedEventArgs.cs
- ResourceAssociationTypeEnd.cs
- Base64Stream.cs
- ToolStripMenuItemCodeDomSerializer.cs
- InheritablePropertyChangeInfo.cs
- NeedSkipTokenVisitor.cs
- GenerateHelper.cs
- ReachSerializationUtils.cs
- HostingEnvironmentWrapper.cs
- CacheAxisQuery.cs
- DynamicQueryableWrapper.cs
- SqlConnectionPoolGroupProviderInfo.cs
- ScriptControl.cs
- AbstractDataSvcMapFileLoader.cs
- X509UI.cs
- OutputCacheSection.cs
- SByteStorage.cs
- HyperLinkStyle.cs
- ComAdminInterfaces.cs
- GenerateTemporaryTargetAssembly.cs
- StatusBarItemAutomationPeer.cs
- RemotingConfiguration.cs
- DeliveryRequirementsAttribute.cs
- TimeSpan.cs
- IgnoreDeviceFilterElement.cs
- DebugTrace.cs
- ToolStripItemImageRenderEventArgs.cs
- RewritingPass.cs
- RowParagraph.cs
- HeaderedItemsControl.cs
- util.cs
- CancellationTokenSource.cs
- RectConverter.cs
- CompilationLock.cs
- AppDomainProtocolHandler.cs
- SR.cs
- WindowClosedEventArgs.cs
- Monitor.cs
- QualifiedCellIdBoolean.cs
- ConfigurationSchemaErrors.cs
- ResourceDisplayNameAttribute.cs
- Binding.cs
- ListParagraph.cs
- XmlStringTable.cs
- SecurityPolicySection.cs
- MethodBuilder.cs
- SecurityContext.cs
- CookieHandler.cs
- RunInstallerAttribute.cs
- TextBox.cs
- RowType.cs
- PaintValueEventArgs.cs
- GridView.cs
- ConnectionStringSettings.cs
- TypeSystem.cs
- ProfessionalColorTable.cs
- OrderPreservingPipeliningSpoolingTask.cs
- StreamUpdate.cs
- Converter.cs
- DataPagerFieldItem.cs
- DetailsViewUpdateEventArgs.cs
- HttpContextServiceHost.cs
- XmlEntity.cs
- XmlSchemaSet.cs
- PointConverter.cs
- InvokeBinder.cs
- RtType.cs
- BinaryCommonClasses.cs
- StrongNameIdentityPermission.cs
- HttpDictionary.cs
- TextInfo.cs
- TokenBasedSetEnumerator.cs
- RichListBox.cs
- DataGridViewCellStyleChangedEventArgs.cs
- SpotLight.cs
- NativeMethods.cs
- CLRBindingWorker.cs
- WindowsFormsHostAutomationPeer.cs
- _OverlappedAsyncResult.cs
- ConsoleKeyInfo.cs
- IntegerCollectionEditor.cs
- XmlSchemaSimpleContent.cs
- SimpleHandlerBuildProvider.cs
- sqlcontext.cs
- MappingItemCollection.cs
- PreservationFileWriter.cs
- PublisherMembershipCondition.cs
- EncoderReplacementFallback.cs
- DeferrableContent.cs
- BindingMemberInfo.cs
- MergePropertyDescriptor.cs
- MenuItem.cs