Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / tx / System / Transactions / Oletx / HandleTable.cs / 1305376 / HandleTable.cs
using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; using System.Transactions.Diagnostics; namespace System.Transactions.Oletx { static class HandleTable { private static DictionaryhandleTable = new Dictionary (256); private static object syncRoot = new object(); private static int currentHandle; public static IntPtr AllocHandle(object target) { lock(syncRoot) { int handle = FindAvailableHandle(); handleTable.Add(handle, target); return new IntPtr(handle); } } public static bool FreeHandle(IntPtr handle) { Debug.Assert(handle != IntPtr.Zero, "handle is invalid"); lock(syncRoot) { return handleTable.Remove(handle.ToInt32()); } } public static object FindHandle(IntPtr handle) { Debug.Assert(handle != IntPtr.Zero, "handle is invalid"); lock(syncRoot) { object target; if (!handleTable.TryGetValue(handle.ToInt32(), out target)) { return null; } return target; } } private static int FindAvailableHandle() { int handle = 0; do { handle = (++currentHandle != 0) ? currentHandle : ++currentHandle; } while(handleTable.ContainsKey(handle)); Debug.Assert(handle != 0, "invalid handle selected"); return handle; } } } // 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
- CompilerScopeManager.cs
- ListViewItemMouseHoverEvent.cs
- ObjectDataSourceWizardForm.cs
- PartialCachingAttribute.cs
- AnnotationStore.cs
- CheckedPointers.cs
- EventLogQuery.cs
- PageAsyncTask.cs
- SponsorHelper.cs
- ProfileParameter.cs
- WorkflowInstanceUnhandledExceptionRecord.cs
- MatrixIndependentAnimationStorage.cs
- CodeGen.cs
- NavigateEvent.cs
- InternalSafeNativeMethods.cs
- WebDisplayNameAttribute.cs
- SqlPersonalizationProvider.cs
- ItemsControlAutomationPeer.cs
- UpDownEvent.cs
- SystemColorTracker.cs
- ChannelBinding.cs
- SamlAssertion.cs
- ParallelSeparator.xaml.cs
- BulletDecorator.cs
- RoleGroup.cs
- Queue.cs
- MaskedTextProvider.cs
- UInt64Converter.cs
- ExpanderAutomationPeer.cs
- StateMachineHistory.cs
- HttpCachePolicy.cs
- ColorAnimationUsingKeyFrames.cs
- UIAgentMonitorHandle.cs
- DataTablePropertyDescriptor.cs
- HierarchicalDataSourceControl.cs
- TextTreeRootTextBlock.cs
- LabelDesigner.cs
- SudsParser.cs
- DataGridToolTip.cs
- GraphicsPath.cs
- FormViewUpdateEventArgs.cs
- ControlBuilderAttribute.cs
- SymLanguageVendor.cs
- DataBoundControlAdapter.cs
- HtmlCalendarAdapter.cs
- HostingPreferredMapPath.cs
- OperationCanceledException.cs
- StorageMappingItemLoader.cs
- SqlDataSourceFilteringEventArgs.cs
- ResourceContainerWrapper.cs
- JsonDeserializer.cs
- CompiledIdentityConstraint.cs
- ConvertersCollection.cs
- Baml2006Reader.cs
- WebPartDescriptionCollection.cs
- Formatter.cs
- RelationshipFixer.cs
- DataFormats.cs
- HttpApplication.cs
- TemplateManager.cs
- EntityContainerRelationshipSet.cs
- ZoomPercentageConverter.cs
- FrameworkElementFactoryMarkupObject.cs
- SqlDataSourceCache.cs
- AppModelKnownContentFactory.cs
- TraceRecord.cs
- DispatcherHookEventArgs.cs
- Guid.cs
- ThreadStaticAttribute.cs
- BuildProviderAppliesToAttribute.cs
- StorageBasedPackageProperties.cs
- GridLength.cs
- Menu.cs
- ProcessHostConfigUtils.cs
- dataSvcMapFileLoader.cs
- MaterialCollection.cs
- TransformCollection.cs
- FrugalList.cs
- DateTimeStorage.cs
- Compress.cs
- WebPartEditorApplyVerb.cs
- XmlSchemaProviderAttribute.cs
- Encoder.cs
- ArraySegment.cs
- ScriptReferenceEventArgs.cs
- ComProxy.cs
- Descriptor.cs
- PropagatorResult.cs
- DataGridItem.cs
- BitVector32.cs
- SafeArchiveContext.cs
- SymmetricAlgorithm.cs
- ListViewItemMouseHoverEvent.cs
- ErrorFormatter.cs
- _ContextAwareResult.cs
- PrintDialogException.cs
- HyperLinkColumn.cs
- WsatAdminException.cs
- _DynamicWinsockMethods.cs
- AddInContractAttribute.cs