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
- RequiredAttributeAttribute.cs
- SmiEventSink_DeferedProcessing.cs
- SurrogateChar.cs
- SafeFileMapViewHandle.cs
- HwndHostAutomationPeer.cs
- XPathArrayIterator.cs
- NavigationWindowAutomationPeer.cs
- VisualBrush.cs
- StringUtil.cs
- DbConnectionOptions.cs
- Cloud.cs
- OracleMonthSpan.cs
- BindingValueChangedEventArgs.cs
- mediaclock.cs
- ObjectViewQueryResultData.cs
- Component.cs
- Misc.cs
- AttributeUsageAttribute.cs
- NumberSubstitution.cs
- ReliableMessagingHelpers.cs
- FileDataSourceCache.cs
- TimeStampChecker.cs
- TextSyndicationContentKindHelper.cs
- UrlPropertyAttribute.cs
- MultilineStringConverter.cs
- ImageConverter.cs
- PhysicalAddress.cs
- RelationshipManager.cs
- ObjectDataSourceDisposingEventArgs.cs
- Utils.cs
- DataControlFieldCollection.cs
- DataRelation.cs
- CodeLabeledStatement.cs
- HtmlImageAdapter.cs
- ReadOnlyDictionary.cs
- ErrorHandler.cs
- DataGridState.cs
- HtmlValidatorAdapter.cs
- ReachFixedDocumentSerializerAsync.cs
- ObjectListDesigner.cs
- RoleBoolean.cs
- ServiceDescriptionSerializer.cs
- DocumentSchemaValidator.cs
- UncommonField.cs
- HebrewCalendar.cs
- Transform.cs
- CryptoConfig.cs
- ArithmeticException.cs
- RequestCachingSection.cs
- UnhandledExceptionEventArgs.cs
- DataGridViewCellEventArgs.cs
- ConcurrentBag.cs
- TimeoutException.cs
- DbBuffer.cs
- InkSerializer.cs
- ParallelTimeline.cs
- ScanQueryOperator.cs
- BitmapSourceSafeMILHandle.cs
- PagerSettings.cs
- SoapMessage.cs
- TimeSpanOrInfiniteValidator.cs
- WebAdminConfigurationHelper.cs
- UnaryExpressionHelper.cs
- LinqDataSource.cs
- ListViewInsertEventArgs.cs
- GenericTypeParameterConverter.cs
- UInt32.cs
- InternalConfigSettingsFactory.cs
- Permission.cs
- OleDbParameterCollection.cs
- ListControl.cs
- CfgParser.cs
- safex509handles.cs
- BinaryFormatterSinks.cs
- BlockUIContainer.cs
- ResourceLoader.cs
- PopupRoot.cs
- AncestorChangedEventArgs.cs
- AuthenticationSection.cs
- X509SecurityTokenProvider.cs
- FixedElement.cs
- OletxTransactionFormatter.cs
- NativeMethods.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- _NativeSSPI.cs
- TTSEngineProxy.cs
- DataListItemEventArgs.cs
- AuthStoreRoleProvider.cs
- HMACMD5.cs
- BmpBitmapDecoder.cs
- X509RecipientCertificateServiceElement.cs
- SimpleHandlerBuildProvider.cs
- isolationinterop.cs
- ValueSerializer.cs
- IntSecurity.cs
- WorkflowOwnershipException.cs
- Typeface.cs
- _ContextAwareResult.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- WsdlImporterElementCollection.cs