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
- WorkflowService.cs
- OutputCacheProfileCollection.cs
- PersianCalendar.cs
- ObjectStorage.cs
- DropTarget.cs
- EntitySetBase.cs
- ByteViewer.cs
- DataGridViewColumnHeaderCell.cs
- _MultipleConnectAsync.cs
- BitmapEffectGeneralTransform.cs
- ListViewItem.cs
- MimeImporter.cs
- ServiceOperationListItem.cs
- DataGridViewTopRowAccessibleObject.cs
- DeflateStream.cs
- FrameworkReadOnlyPropertyMetadata.cs
- UntrustedRecipientException.cs
- SpeakCompletedEventArgs.cs
- RawKeyboardInputReport.cs
- ThumbAutomationPeer.cs
- StateRuntime.cs
- AdRotator.cs
- GenericEnumerator.cs
- ValidationError.cs
- BindingManagerDataErrorEventArgs.cs
- NonSerializedAttribute.cs
- CacheEntry.cs
- DataGridViewColumn.cs
- TabControlDesigner.cs
- SAPICategories.cs
- SchemaNotation.cs
- Command.cs
- IDReferencePropertyAttribute.cs
- ActivityPreviewDesigner.cs
- WorkflowDesignerColors.cs
- TypeSchema.cs
- AssemblyInfo.cs
- BulletedList.cs
- BitmapEffectInputData.cs
- ResourceLoader.cs
- ResetableIterator.cs
- LinearGradientBrush.cs
- ConsoleCancelEventArgs.cs
- HtmlTableCell.cs
- FontNamesConverter.cs
- Invariant.cs
- BindingsSection.cs
- IApplicationTrustManager.cs
- Debugger.cs
- DataGridViewCell.cs
- GACIdentityPermission.cs
- NCryptNative.cs
- CodeIdentifier.cs
- WebServiceClientProxyGenerator.cs
- AssociativeAggregationOperator.cs
- DeferredReference.cs
- Random.cs
- DataFormats.cs
- HtmlLink.cs
- TextRangeAdaptor.cs
- FacetChecker.cs
- StreamWriter.cs
- LinearGradientBrush.cs
- DiffuseMaterial.cs
- CodeSnippetCompileUnit.cs
- ObjectItemCollection.cs
- ValueChangedEventManager.cs
- SpecialFolderEnumConverter.cs
- JournalEntryListConverter.cs
- PlainXmlSerializer.cs
- ContentFilePart.cs
- SqlMethodCallConverter.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- _DigestClient.cs
- ProtocolsConfigurationEntry.cs
- ComboBoxItem.cs
- KeyPressEvent.cs
- WsdlBuildProvider.cs
- DbResourceAllocator.cs
- RemotingSurrogateSelector.cs
- IPipelineRuntime.cs
- WebServiceHostFactory.cs
- NavigationWindowAutomationPeer.cs
- MonitoringDescriptionAttribute.cs
- IndexerNameAttribute.cs
- CommentGlyph.cs
- PropVariant.cs
- PropertyGridCommands.cs
- RoleManagerEventArgs.cs
- ResourcePool.cs
- HitTestResult.cs
- TreeViewEvent.cs
- SrgsText.cs
- RegistryDataKey.cs
- FormViewUpdatedEventArgs.cs
- Binding.cs
- PtsHost.cs
- HwndProxyElementProvider.cs
- SqlDataSourceQuery.cs
- VideoDrawing.cs