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
- MetadataPropertyAttribute.cs
- BufferModeSettings.cs
- EntitySqlException.cs
- RawAppCommandInputReport.cs
- ComplexPropertyEntry.cs
- ElementHostPropertyMap.cs
- Grammar.cs
- SafeCertificateStore.cs
- NotifyCollectionChangedEventArgs.cs
- CodeEntryPointMethod.cs
- FactoryGenerator.cs
- ResourceReferenceExpressionConverter.cs
- ObjectPersistData.cs
- SqlHelper.cs
- OleDbCommandBuilder.cs
- ComponentResourceManager.cs
- Form.cs
- XmlTextReader.cs
- FontWeightConverter.cs
- HtmlElement.cs
- SpellerStatusTable.cs
- SharedStatics.cs
- CompilerTypeWithParams.cs
- CurrentChangingEventArgs.cs
- Screen.cs
- ButtonChrome.cs
- EncoderNLS.cs
- PreservationFileReader.cs
- BinaryObjectReader.cs
- BevelBitmapEffect.cs
- SortableBindingList.cs
- DataControlButton.cs
- SByteStorage.cs
- ClientSettingsSection.cs
- PhonemeConverter.cs
- InternalBufferOverflowException.cs
- CharacterBuffer.cs
- ListViewTableRow.cs
- DrawItemEvent.cs
- ToolStripDropDownButton.cs
- VarInfo.cs
- BooleanSwitch.cs
- ListViewPagedDataSource.cs
- ObjectSecurity.cs
- WebPartDisplayModeEventArgs.cs
- MailAddress.cs
- Encoder.cs
- ObjectCloneHelper.cs
- ReachPageContentSerializerAsync.cs
- SystemFonts.cs
- DesignerActionListCollection.cs
- SqlDuplicator.cs
- BitVector32.cs
- MouseEvent.cs
- UpDownBase.cs
- DataBindingValueUIHandler.cs
- PropertyTabChangedEvent.cs
- ThreadStaticAttribute.cs
- LinearGradientBrush.cs
- DirtyTextRange.cs
- GroupBox.cs
- HandledMouseEvent.cs
- GlyphRun.cs
- SafePipeHandle.cs
- x509store.cs
- CheckBoxRenderer.cs
- webclient.cs
- BlurEffect.cs
- TokenBasedSetEnumerator.cs
- Peer.cs
- AsymmetricKeyExchangeFormatter.cs
- RectKeyFrameCollection.cs
- ObjectTypeMapping.cs
- CurrentChangingEventArgs.cs
- DbConnectionPoolOptions.cs
- BinHexEncoder.cs
- FieldValue.cs
- XmlBinaryReaderSession.cs
- ColorInterpolationModeValidation.cs
- ServiceHttpModule.cs
- LicFileLicenseProvider.cs
- SamlAttribute.cs
- FileChangesMonitor.cs
- Binding.cs
- SHA1Managed.cs
- SortedDictionary.cs
- Bookmark.cs
- OleDbDataAdapter.cs
- ProtocolReflector.cs
- JapaneseCalendar.cs
- SubMenuStyleCollection.cs
- XmlNullResolver.cs
- Constants.cs
- Transform3DGroup.cs
- RelatedEnd.cs
- DbConnectionPoolIdentity.cs
- SmtpFailedRecipientException.cs
- Soap.cs
- DataControlImageButton.cs
- TextFormatterContext.cs