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
- ObjectMemberMapping.cs
- KeyedCollection.cs
- ScriptModule.cs
- SafeHandle.cs
- TextRangeEditLists.cs
- BufferManager.cs
- ProgressBar.cs
- DesignOnlyAttribute.cs
- ErrorCodes.cs
- DecoderBestFitFallback.cs
- ClientCredentialsSecurityTokenManager.cs
- SecurityRuntime.cs
- querybuilder.cs
- ScriptingWebServicesSectionGroup.cs
- X509UI.cs
- RtType.cs
- KnownBoxes.cs
- FixedTextView.cs
- FormViewRow.cs
- FrameworkContentElement.cs
- __ConsoleStream.cs
- SchemaNotation.cs
- CustomBindingElementCollection.cs
- TextSelection.cs
- SlotInfo.cs
- ViewEventArgs.cs
- ChameleonKey.cs
- ListDictionary.cs
- QuestionEventArgs.cs
- EntityDataSourceColumn.cs
- MergeFilterQuery.cs
- ExpandableObjectConverter.cs
- TreeNodeClickEventArgs.cs
- CapabilitiesPattern.cs
- AppearanceEditorPart.cs
- HebrewNumber.cs
- Bits.cs
- RedirectionProxy.cs
- RuntimeHelpers.cs
- ScopedKnownTypes.cs
- AdornedElementPlaceholder.cs
- DrawToolTipEventArgs.cs
- ModuleConfigurationInfo.cs
- ProfileEventArgs.cs
- XmlSerializationGeneratedCode.cs
- DelegateBodyWriter.cs
- CodeIterationStatement.cs
- FunctionParameter.cs
- PersonalizableTypeEntry.cs
- OracleParameterCollection.cs
- WebBaseEventKeyComparer.cs
- GeneralTransform3DGroup.cs
- Label.cs
- DesigntimeLicenseContext.cs
- OleDbConnectionFactory.cs
- ListBoxDesigner.cs
- PackageFilter.cs
- DateTimeValueSerializerContext.cs
- HttpPostServerProtocol.cs
- XmlDataLoader.cs
- MetabaseSettingsIis7.cs
- DataGridViewColumnConverter.cs
- OptionUsage.cs
- MemberDomainMap.cs
- ObjectTokenCategory.cs
- CatalogZoneBase.cs
- XmlSchemaSubstitutionGroup.cs
- MembershipPasswordException.cs
- NativeCompoundFileAPIs.cs
- ThicknessConverter.cs
- CodeTypeParameterCollection.cs
- AsyncStreamReader.cs
- WebEventCodes.cs
- TypeConverterAttribute.cs
- IndexObject.cs
- _WinHttpWebProxyDataBuilder.cs
- HtmlInputButton.cs
- DerivedKeySecurityToken.cs
- EncryptedPackageFilter.cs
- DeclarationUpdate.cs
- ClassHandlersStore.cs
- AsyncOperationManager.cs
- SymmetricAlgorithm.cs
- WriterOutput.cs
- NotCondition.cs
- DataRowCollection.cs
- HttpRequestMessageProperty.cs
- UserControlCodeDomTreeGenerator.cs
- DataSourceCacheDurationConverter.cs
- LookupBindingPropertiesAttribute.cs
- PasswordPropertyTextAttribute.cs
- Header.cs
- Token.cs
- BidirectionalDictionary.cs
- HybridObjectCache.cs
- ComponentEvent.cs
- NullExtension.cs
- iisPickupDirectory.cs
- ActiveXContainer.cs
- Sql8ConformanceChecker.cs