Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- MatrixValueSerializer.cs
- WMIInterop.cs
- ConstraintEnumerator.cs
- ProvideValueServiceProvider.cs
- FastEncoder.cs
- XslTransformFileEditor.cs
- OrderedDictionaryStateHelper.cs
- SQLRoleProvider.cs
- FastPropertyAccessor.cs
- ViewSimplifier.cs
- TcpServerChannel.cs
- EditorZoneBase.cs
- RelationshipNavigation.cs
- httpserverutility.cs
- WindowsListViewItemCheckBox.cs
- BatchWriter.cs
- ForceCopyBuildProvider.cs
- TypographyProperties.cs
- RequestSecurityTokenForGetBrowserToken.cs
- SqlDataSourceCache.cs
- CompilationUtil.cs
- ResourceAttributes.cs
- TextContainerChangeEventArgs.cs
- Point3DValueSerializer.cs
- LocationSectionRecord.cs
- PersonalizationState.cs
- MenuItemBindingCollection.cs
- WebServiceMethodData.cs
- XmlQueryType.cs
- WinFormsComponentEditor.cs
- PropertyBuilder.cs
- XmlDataSource.cs
- DependencyPropertyDescriptor.cs
- sqlinternaltransaction.cs
- DetailsView.cs
- CacheMemory.cs
- OLEDB_Util.cs
- QueryGeneratorBase.cs
- SmtpDigestAuthenticationModule.cs
- RuleSetBrowserDialog.cs
- ApplicationFileCodeDomTreeGenerator.cs
- ScrollViewerAutomationPeer.cs
- ComponentChangingEvent.cs
- IriParsingElement.cs
- URIFormatException.cs
- XmlSignificantWhitespace.cs
- IImplicitResourceProvider.cs
- MediaScriptCommandRoutedEventArgs.cs
- SettingsPropertyCollection.cs
- JoinTreeSlot.cs
- WindowsListViewItemCheckBox.cs
- HtmlTableRow.cs
- ScriptControlManager.cs
- PtsCache.cs
- MetadataArtifactLoaderResource.cs
- ManifestSignatureInformation.cs
- TypeHelpers.cs
- UIHelper.cs
- SafeArrayTypeMismatchException.cs
- DesignSurface.cs
- FilterableAttribute.cs
- DoubleMinMaxAggregationOperator.cs
- ConsumerConnectionPoint.cs
- SessionStateItemCollection.cs
- QueueAccessMode.cs
- BrowserInteropHelper.cs
- Geometry3D.cs
- XmlIgnoreAttribute.cs
- HostedHttpRequestAsyncResult.cs
- _NtlmClient.cs
- ObjectListCommandEventArgs.cs
- SystemWebCachingSectionGroup.cs
- XPathNodeHelper.cs
- SqlInternalConnectionSmi.cs
- ConfigurationStrings.cs
- AtomEntry.cs
- StyleModeStack.cs
- DesigntimeLicenseContext.cs
- TaskFormBase.cs
- InputBindingCollection.cs
- HtmlTernaryTree.cs
- DrawingBrush.cs
- StorageEntityTypeMapping.cs
- SchemaNames.cs
- InputQueue.cs
- ImageInfo.cs
- IteratorFilter.cs
- EntityReference.cs
- SrgsText.cs
- AuthenticationConfig.cs
- WebBrowserContainer.cs
- IItemContainerGenerator.cs
- DebuggerAttributes.cs
- RoleManagerModule.cs
- PriorityRange.cs
- SpanIndex.cs
- RSAProtectedConfigurationProvider.cs
- FixedHyperLink.cs
- HtmlElementCollection.cs
- ParallelDesigner.xaml.cs