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
- JoinSymbol.cs
- VisemeEventArgs.cs
- backend.cs
- FileIOPermission.cs
- ResolveMatchesMessageCD1.cs
- CultureInfo.cs
- UniqueEventHelper.cs
- TransformerConfigurationWizardBase.cs
- FormViewInsertedEventArgs.cs
- ScriptingScriptResourceHandlerSection.cs
- DoubleAnimationBase.cs
- PersonalizationEntry.cs
- DataControlLinkButton.cs
- DictationGrammar.cs
- CreateRefExpr.cs
- AsymmetricKeyExchangeFormatter.cs
- Matrix3DStack.cs
- RepeatButton.cs
- initElementDictionary.cs
- VisualBrush.cs
- DataGridPagerStyle.cs
- SequentialWorkflowRootDesigner.cs
- SerializationSectionGroup.cs
- RNGCryptoServiceProvider.cs
- WCFBuildProvider.cs
- SmiContext.cs
- IsolatedStorageFile.cs
- WebHttpDispatchOperationSelector.cs
- WebPartConnectionsConnectVerb.cs
- SymbolDocumentGenerator.cs
- ConfigurationElementCollection.cs
- ProfilePropertySettings.cs
- SoapFault.cs
- CannotUnloadAppDomainException.cs
- precedingsibling.cs
- DesigntimeLicenseContext.cs
- DbParameterHelper.cs
- ComponentCommands.cs
- regiisutil.cs
- MethodExpression.cs
- LookupNode.cs
- Mouse.cs
- ScriptServiceAttribute.cs
- XpsTokenContext.cs
- DivideByZeroException.cs
- ActivationArguments.cs
- Cursor.cs
- PackageController.cs
- TCEAdapterGenerator.cs
- ResourceDescriptionAttribute.cs
- MetadataItemEmitter.cs
- PackagePartCollection.cs
- TransportationConfigurationTypeInstallComponent.cs
- RijndaelManaged.cs
- DescendantQuery.cs
- TypeUtils.cs
- MultilineStringConverter.cs
- WindowsTitleBar.cs
- MimeParameter.cs
- UnsafeNativeMethods.cs
- HyperLinkField.cs
- StringArrayConverter.cs
- RecordConverter.cs
- DiffuseMaterial.cs
- Evaluator.cs
- PatternMatcher.cs
- MemoryRecordBuffer.cs
- ReliabilityContractAttribute.cs
- XmlSubtreeReader.cs
- DataGridViewColumnHeaderCell.cs
- Classification.cs
- panel.cs
- Accessible.cs
- hebrewshape.cs
- KeyConstraint.cs
- SqlReferenceCollection.cs
- WindowsSolidBrush.cs
- JpegBitmapEncoder.cs
- unsafenativemethodstextservices.cs
- OleDbPermission.cs
- AutomationPropertyInfo.cs
- Message.cs
- BevelBitmapEffect.cs
- UIElement3D.cs
- RepeaterItemCollection.cs
- StorageAssociationSetMapping.cs
- RuntimeConfig.cs
- WorkerRequest.cs
- _DigestClient.cs
- SafeRightsManagementQueryHandle.cs
- DeflateStreamAsyncResult.cs
- SettingsPropertyWrongTypeException.cs
- TerminateDesigner.cs
- IncrementalReadDecoders.cs
- CreatingCookieEventArgs.cs
- TileModeValidation.cs
- ConfigurationSettings.cs
- XmlHierarchicalDataSourceView.cs
- DataConnectionHelper.cs
- ColorTranslator.cs