Code:
/ 4.0 / 4.0 / 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. 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 Dictionary handleTable = 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
- MDIWindowDialog.cs
- Int64Animation.cs
- ConditionValidator.cs
- ComNativeDescriptor.cs
- UITypeEditor.cs
- CryptoHelper.cs
- SizeAnimationBase.cs
- PasswordTextNavigator.cs
- RoleGroupCollection.cs
- PerspectiveCamera.cs
- Calendar.cs
- MULTI_QI.cs
- InvalidWorkflowException.cs
- Pen.cs
- EncryptedKeyIdentifierClause.cs
- ValidationSummary.cs
- MetadataItemSerializer.cs
- ClientFormsAuthenticationCredentials.cs
- DbDeleteCommandTree.cs
- DataGridViewTextBoxColumn.cs
- AmbientValueAttribute.cs
- CacheOutputQuery.cs
- StreamResourceInfo.cs
- SynchronizedInputHelper.cs
- AsymmetricSignatureDeformatter.cs
- EndpointPerformanceCounters.cs
- CompletionProxy.cs
- PageAdapter.cs
- AsyncWaitHandle.cs
- InputScopeManager.cs
- TransformConverter.cs
- Compilation.cs
- MatrixAnimationBase.cs
- MobileUserControl.cs
- SerializationEventsCache.cs
- InfoCard.cs
- SemanticResolver.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- ChannelSettingsElement.cs
- JsonDeserializer.cs
- TextPatternIdentifiers.cs
- ColumnWidthChangingEvent.cs
- TextFormatterContext.cs
- RuntimeResourceSet.cs
- CodeIdentifiers.cs
- EntityCollection.cs
- InternalConfigHost.cs
- ThreadPool.cs
- AncestorChangedEventArgs.cs
- RegexCharClass.cs
- SmtpNtlmAuthenticationModule.cs
- HttpResponseInternalBase.cs
- ObjectResult.cs
- LinkLabelLinkClickedEvent.cs
- BitmapEffectInputData.cs
- FullTrustAssembly.cs
- CodeGroup.cs
- RuleProcessor.cs
- ApplicationHost.cs
- FollowerQueueCreator.cs
- Button.cs
- WebColorConverter.cs
- HtmlControlPersistable.cs
- ADRole.cs
- VisualStyleElement.cs
- CommandDevice.cs
- ECDiffieHellmanCngPublicKey.cs
- TextDpi.cs
- SmiMetaDataProperty.cs
- BlobPersonalizationState.cs
- FrameworkElementAutomationPeer.cs
- SafeReversePInvokeHandle.cs
- KeySplineConverter.cs
- CodeTypeMemberCollection.cs
- WebPartEventArgs.cs
- SqlDependencyListener.cs
- XmlILConstructAnalyzer.cs
- XmlElementAttribute.cs
- ToolStripItemCollection.cs
- WinEventTracker.cs
- MergeFilterQuery.cs
- ZipPackagePart.cs
- ISFTagAndGuidCache.cs
- SpellerHighlightLayer.cs
- Application.cs
- AsymmetricKeyExchangeFormatter.cs
- ManifestResourceInfo.cs
- DoubleAnimationClockResource.cs
- SessionStateUtil.cs
- DefinitionBase.cs
- GridViewCommandEventArgs.cs
- LoginView.cs
- CaseInsensitiveComparer.cs
- LocalValueEnumerator.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- EmbeddedMailObject.cs
- SourceFileInfo.cs
- ScrollProperties.cs
- ServicePointManagerElement.cs
- ModelVisual3D.cs