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
- CookieHandler.cs
- SqlMultiplexer.cs
- FlowchartStart.xaml.cs
- SimpleBitVector32.cs
- RoutedEventConverter.cs
- ArrayMergeHelper.cs
- HTMLTagNameToTypeMapper.cs
- InsufficientExecutionStackException.cs
- SafeEventLogWriteHandle.cs
- BCLDebug.cs
- Parameter.cs
- CrossSiteScriptingValidation.cs
- versioninfo.cs
- Events.cs
- DataRelationCollection.cs
- PropertyTabAttribute.cs
- IntegerValidatorAttribute.cs
- SkinBuilder.cs
- RectAnimationClockResource.cs
- RangeEnumerable.cs
- BrushValueSerializer.cs
- SequentialOutput.cs
- ColorTransformHelper.cs
- _TLSstream.cs
- XmlTextReader.cs
- GeometryCombineModeValidation.cs
- MessageQueuePermissionEntryCollection.cs
- SqlConnectionFactory.cs
- DataGridViewComboBoxColumn.cs
- PropertyRecord.cs
- DeflateEmulationStream.cs
- AssemblyCollection.cs
- TypedElement.cs
- DispatchChannelSink.cs
- FrameworkContextData.cs
- WindowsAltTab.cs
- FrameworkElement.cs
- Model3DGroup.cs
- MessageQueueCriteria.cs
- SessionStateUtil.cs
- FontFamilyConverter.cs
- ScalarType.cs
- SqlBinder.cs
- InstancePersistenceEvent.cs
- DocumentSchemaValidator.cs
- ConfigsHelper.cs
- FixedNode.cs
- OverrideMode.cs
- DataPagerCommandEventArgs.cs
- AbsoluteQuery.cs
- X509SecurityTokenAuthenticator.cs
- DefaultProxySection.cs
- TypeSystem.cs
- SafeNativeMethods.cs
- TreeIterator.cs
- RoutedEventHandlerInfo.cs
- HttpHandlersSection.cs
- ReachDocumentSequenceSerializer.cs
- ExpandSegmentCollection.cs
- TraceUtility.cs
- EventMappingSettings.cs
- MatrixKeyFrameCollection.cs
- ContentValidator.cs
- TokenizerHelper.cs
- SocketElement.cs
- Schedule.cs
- MemberAccessException.cs
- SqlConnectionPoolGroupProviderInfo.cs
- DelegatingConfigHost.cs
- CodeDirectionExpression.cs
- AssertValidation.cs
- SevenBitStream.cs
- AbstractDataSvcMapFileLoader.cs
- HtmlValidatorAdapter.cs
- RecordManager.cs
- SafeLibraryHandle.cs
- ZipFileInfoCollection.cs
- TabControl.cs
- SqlWebEventProvider.cs
- GlyphInfoList.cs
- HttpCacheParams.cs
- PackageDigitalSignature.cs
- XamlGridLengthSerializer.cs
- ServiceNameElementCollection.cs
- ScrollContentPresenter.cs
- ChildChangedEventArgs.cs
- ObjectSecurity.cs
- TaskExceptionHolder.cs
- Variable.cs
- XmlUtil.cs
- xml.cs
- LabelLiteral.cs
- ErrorWrapper.cs
- UserPersonalizationStateInfo.cs
- Tablet.cs
- WCFServiceClientProxyGenerator.cs
- KnownColorTable.cs
- XPathScanner.cs
- LinqDataSourceSelectEventArgs.cs
- XmlElement.cs