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
- LoginView.cs
- ReferenceList.cs
- ChtmlPageAdapter.cs
- cache.cs
- StringResourceManager.cs
- ComplexLine.cs
- OutgoingWebRequestContext.cs
- FileDataSourceCache.cs
- Page.cs
- Maps.cs
- Size.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- DesignerDataRelationship.cs
- StringSorter.cs
- TableFieldsEditor.cs
- RequestTimeoutManager.cs
- CookieProtection.cs
- XmlComment.cs
- CryptoApi.cs
- InvokeSchedule.cs
- Int16Animation.cs
- UpdateProgress.cs
- TrackingDataItem.cs
- SoapFault.cs
- UpdateEventArgs.cs
- PersonalizationStateQuery.cs
- WriteLineDesigner.xaml.cs
- EventSource.cs
- LinqDataSourceDisposeEventArgs.cs
- UnsafeNativeMethods.cs
- CmsUtils.cs
- ColorConvertedBitmapExtension.cs
- Configuration.cs
- EntitySqlQueryBuilder.cs
- EnumUnknown.cs
- SizeConverter.cs
- Registry.cs
- HttpApplication.cs
- FieldMetadata.cs
- ComponentDispatcherThread.cs
- DataBoundControlHelper.cs
- StreamHelper.cs
- MergeFailedEvent.cs
- ControlCollection.cs
- PauseStoryboard.cs
- SelectionListDesigner.cs
- CanExecuteRoutedEventArgs.cs
- PrePrepareMethodAttribute.cs
- PersonalizationEntry.cs
- TdsParserStaticMethods.cs
- BitVector32.cs
- WindowsListViewItem.cs
- TextProviderWrapper.cs
- TextParagraphView.cs
- XmlIncludeAttribute.cs
- QueryPageSettingsEventArgs.cs
- _BufferOffsetSize.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- DirectoryInfo.cs
- DoubleAnimation.cs
- SiteMapDataSourceView.cs
- DependencyPropertyKind.cs
- AdornerHitTestResult.cs
- smtppermission.cs
- SocketPermission.cs
- ScalarOps.cs
- TableRowGroup.cs
- XmlSchemaSimpleContentExtension.cs
- SynchronizedDispatch.cs
- SqlCrossApplyToCrossJoin.cs
- CodeTypeMember.cs
- AtomPub10ServiceDocumentFormatter.cs
- SuppressMessageAttribute.cs
- smtpconnection.cs
- EnterpriseServicesHelper.cs
- ConfigurationSectionHelper.cs
- KnownBoxes.cs
- RawUIStateInputReport.cs
- Attributes.cs
- CompilerWrapper.cs
- StoryFragments.cs
- EdmRelationshipRoleAttribute.cs
- XmlSchemaChoice.cs
- DocumentPageHost.cs
- Int16KeyFrameCollection.cs
- PropertyChangedEventArgs.cs
- WorkflowServiceHostFactory.cs
- SpecularMaterial.cs
- MimeFormReflector.cs
- Application.cs
- SchemaAttDef.cs
- RetriableClipboard.cs
- DecimalStorage.cs
- ToolStripGrip.cs
- ScopedKnownTypes.cs
- WaitHandleCannotBeOpenedException.cs
- AccessedThroughPropertyAttribute.cs
- UriExt.cs
- InstanceKeyCompleteException.cs
- XmlSchemaSimpleTypeRestriction.cs