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
- TimeSpanSecondsConverter.cs
- PtsCache.cs
- PackWebResponse.cs
- DataError.cs
- CmsInterop.cs
- TemplateParser.cs
- CodeDomSerializationProvider.cs
- ThreadStartException.cs
- CompositeActivityTypeDescriptor.cs
- CompoundFileIOPermission.cs
- UnsafeNativeMethods.cs
- ConstructorNeedsTagAttribute.cs
- OperationInfo.cs
- BamlWriter.cs
- OdbcConnectionHandle.cs
- bidPrivateBase.cs
- LinqDataSourceDisposeEventArgs.cs
- Condition.cs
- TypographyProperties.cs
- TemplateKeyConverter.cs
- FirstMatchCodeGroup.cs
- UniqueEventHelper.cs
- SmtpTransport.cs
- httpapplicationstate.cs
- _ChunkParse.cs
- CompletionProxy.cs
- HitTestFilterBehavior.cs
- DurableRuntimeValidator.cs
- RuntimeIdentifierPropertyAttribute.cs
- IndexedString.cs
- ToolStripSystemRenderer.cs
- ThreadStateException.cs
- DrawingVisualDrawingContext.cs
- MenuItemBindingCollection.cs
- LayoutSettings.cs
- XmlAttributeAttribute.cs
- DataGridColumn.cs
- TraceLevelHelper.cs
- ConnectionPoolManager.cs
- OleDbTransaction.cs
- AudioFileOut.cs
- DesignOnlyAttribute.cs
- ColumnPropertiesGroup.cs
- WebSysDefaultValueAttribute.cs
- QueryContinueDragEvent.cs
- StylusShape.cs
- AnnouncementService.cs
- ThreadPoolTaskScheduler.cs
- DropAnimation.xaml.cs
- Annotation.cs
- _BaseOverlappedAsyncResult.cs
- InputLanguageEventArgs.cs
- TokenBasedSetEnumerator.cs
- TextParagraphProperties.cs
- GenericsInstances.cs
- NetDataContractSerializer.cs
- control.ime.cs
- DataColumnCollection.cs
- FunctionDescription.cs
- ByteStreamGeometryContext.cs
- TypeSystem.cs
- LocationReferenceEnvironment.cs
- RichTextBoxDesigner.cs
- ToolStripSplitStackLayout.cs
- EtwTrackingBehaviorElement.cs
- AuthorizationPolicyTypeElementCollection.cs
- ZipArchive.cs
- EventInfo.cs
- ASCIIEncoding.cs
- UInt16Storage.cs
- TypeSemantics.cs
- WizardForm.cs
- ProviderException.cs
- MemberExpressionHelper.cs
- BuildResult.cs
- InternalControlCollection.cs
- AnnotationHelper.cs
- MenuItemCollection.cs
- CqlGenerator.cs
- SqlInternalConnectionTds.cs
- DummyDataSource.cs
- HttpWebRequest.cs
- NavigationCommands.cs
- WebResourceAttribute.cs
- Image.cs
- ConfigXmlCDataSection.cs
- CellConstantDomain.cs
- SoapFault.cs
- columnmapfactory.cs
- CngKeyCreationParameters.cs
- DiscoveryUtility.cs
- Matrix.cs
- DictionaryBase.cs
- ConsoleKeyInfo.cs
- TraceInternal.cs
- BorderGapMaskConverter.cs
- Parameter.cs
- SecurityContext.cs
- SchemaManager.cs
- FtpCachePolicyElement.cs