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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CalendarDataBindingHandler.cs
- ShaperBuffers.cs
- CommandBindingCollection.cs
- XmlStringTable.cs
- XmlDeclaration.cs
- DocComment.cs
- Events.cs
- WinEventHandler.cs
- ListViewUpdateEventArgs.cs
- GPPOINT.cs
- MergeLocalizationDirectives.cs
- WorkflowServiceHostFactory.cs
- SqlEnums.cs
- UnsafeNativeMethods.cs
- DataGridHeaderBorder.cs
- SendActivityDesignerTheme.cs
- WindowPattern.cs
- TimeSpanStorage.cs
- IISMapPath.cs
- Currency.cs
- WebRequestModulesSection.cs
- followingquery.cs
- WarningException.cs
- CanonicalFormWriter.cs
- ManualResetEvent.cs
- DirectoryInfo.cs
- QilTargetType.cs
- CodeIdentifiers.cs
- BaseTemplateBuildProvider.cs
- DataGridColumnDropSeparator.cs
- FlowDocumentFormatter.cs
- Emitter.cs
- DetailsViewModeEventArgs.cs
- AnimationClockResource.cs
- ThreadInterruptedException.cs
- GridViewPageEventArgs.cs
- DeriveBytes.cs
- HandlerFactoryCache.cs
- StrokeSerializer.cs
- VirtualPathProvider.cs
- RuntimeCompatibilityAttribute.cs
- HttpWebResponse.cs
- ContentTypeSettingClientMessageFormatter.cs
- MultipleFilterMatchesException.cs
- SqlConnectionStringBuilder.cs
- ApplicationHost.cs
- IpcClientManager.cs
- TileModeValidation.cs
- PointAnimationUsingPath.cs
- DataSysAttribute.cs
- HorizontalAlignConverter.cs
- DirectionalLight.cs
- Misc.cs
- ValidationHelper.cs
- OleDbCommand.cs
- TableColumnCollection.cs
- FileIOPermission.cs
- CursorConverter.cs
- DataPagerFieldCommandEventArgs.cs
- MultitargetUtil.cs
- UserControlCodeDomTreeGenerator.cs
- ProbeDuplex11AsyncResult.cs
- PrivilegeNotHeldException.cs
- DependencyPropertyChangedEventArgs.cs
- TcpClientChannel.cs
- LoadedOrUnloadedOperation.cs
- WebPartZoneCollection.cs
- ArrangedElementCollection.cs
- FamilyMapCollection.cs
- ConnectionStringSettingsCollection.cs
- HttpCachePolicyWrapper.cs
- StyleCollection.cs
- TimersDescriptionAttribute.cs
- NGCSerializerAsync.cs
- PageThemeParser.cs
- InstanceCreationEditor.cs
- XmlIncludeAttribute.cs
- SystemKeyConverter.cs
- BrowsableAttribute.cs
- UrlMapping.cs
- DrawTreeNodeEventArgs.cs
- GroupLabel.cs
- ZeroOpNode.cs
- InstanceData.cs
- SpAudioStreamWrapper.cs
- TraceEventCache.cs
- OdbcConnectionOpen.cs
- SolidColorBrush.cs
- HttpServerUtilityWrapper.cs
- GenericWebPart.cs
- AttributeQuery.cs
- SlotInfo.cs
- DataGridViewCellFormattingEventArgs.cs
- BinaryCommonClasses.cs
- QueryCacheKey.cs
- ImagingCache.cs
- UidManager.cs
- VisualCollection.cs
- DBPropSet.cs
- HtmlInputControl.cs