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
- ClickablePoint.cs
- BamlRecordReader.cs
- LocationUpdates.cs
- HtmlAnchor.cs
- TransformerInfoCollection.cs
- ConvertersCollection.cs
- PenContexts.cs
- VarRefManager.cs
- Int16.cs
- ModelMemberCollection.cs
- VisualStyleRenderer.cs
- oledbmetadatacolumnnames.cs
- DeploymentSectionCache.cs
- IOThreadScheduler.cs
- PageContentCollection.cs
- StoreAnnotationsMap.cs
- FixedSOMPage.cs
- CharUnicodeInfo.cs
- VBCodeProvider.cs
- LoginViewDesigner.cs
- CustomPopupPlacement.cs
- StatusBarAutomationPeer.cs
- StringValidatorAttribute.cs
- XslCompiledTransform.cs
- DnsPermission.cs
- ProjectionCamera.cs
- XamlGridLengthSerializer.cs
- CurrencyManager.cs
- WebPartHeaderCloseVerb.cs
- ApplicationFileCodeDomTreeGenerator.cs
- TabControl.cs
- BindUriHelper.cs
- WebPartsPersonalization.cs
- _ConnectionGroup.cs
- SkewTransform.cs
- ExpressionNormalizer.cs
- ArrayTypeMismatchException.cs
- XmlDataLoader.cs
- AppDomainUnloadedException.cs
- XmlChoiceIdentifierAttribute.cs
- TextBoxDesigner.cs
- FontStretch.cs
- InternalPolicyElement.cs
- DBConnectionString.cs
- NetworkAddressChange.cs
- RightsManagementEncryptedStream.cs
- ToolStripDropDownDesigner.cs
- BinHexEncoder.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- ComponentManagerBroker.cs
- ScriptDescriptor.cs
- ScalarType.cs
- DrawingContextDrawingContextWalker.cs
- Tokenizer.cs
- DateTimeFormatInfo.cs
- SyndicationSerializer.cs
- InputLanguageCollection.cs
- DataSysAttribute.cs
- ApplicationBuildProvider.cs
- ContextDataSourceContextData.cs
- ZipIOExtraFieldZip64Element.cs
- CommandTreeTypeHelper.cs
- StreamReader.cs
- LinqDataSourceContextEventArgs.cs
- StatusBarDrawItemEvent.cs
- GroupBoxRenderer.cs
- ColorConvertedBitmapExtension.cs
- SchemaMapping.cs
- LogManagementAsyncResult.cs
- RayMeshGeometry3DHitTestResult.cs
- SqlDataSourceQueryEditorForm.cs
- ObjectStateFormatter.cs
- QueryCacheManager.cs
- CodeDirectoryCompiler.cs
- SpeechSeg.cs
- NameNode.cs
- EncoderNLS.cs
- Point4D.cs
- SqlHelper.cs
- StandardCommands.cs
- WebReference.cs
- webbrowsersite.cs
- Form.cs
- TypeToArgumentTypeConverter.cs
- CommandLibraryHelper.cs
- DelayedRegex.cs
- AttributeEmitter.cs
- MetabaseReader.cs
- SQLGuid.cs
- GeneralTransform3DGroup.cs
- SystemInformation.cs
- ViewBase.cs
- NamedPermissionSet.cs
- ReadOnlyPropertyMetadata.cs
- PriorityQueue.cs
- DocumentPageHost.cs
- MarkupObject.cs
- RunInstallerAttribute.cs
- ConsumerConnectionPointCollection.cs
- StrokeCollection.cs