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 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
- SimplePropertyEntry.cs
- EpmContentDeSerializerBase.cs
- ChannelSinkStacks.cs
- ClosableStream.cs
- ClientCultureInfo.cs
- Version.cs
- BindingOperations.cs
- LineGeometry.cs
- EdmType.cs
- HybridWebProxyFinder.cs
- Utils.cs
- EpmSourceTree.cs
- TrustLevelCollection.cs
- JapaneseCalendar.cs
- ExpressionVisitorHelpers.cs
- NameSpaceExtractor.cs
- InternalRelationshipCollection.cs
- XslNumber.cs
- UrlParameterReader.cs
- SqlBulkCopyColumnMapping.cs
- ToolBarButton.cs
- SecureEnvironment.cs
- ProjectionPlan.cs
- ContractHandle.cs
- ValidatingPropertiesEventArgs.cs
- RegistryKey.cs
- UrlAuthFailedErrorFormatter.cs
- ConnectionPointCookie.cs
- XmlDataSourceNodeDescriptor.cs
- MouseOverProperty.cs
- RegexRunnerFactory.cs
- FileEnumerator.cs
- BitmapData.cs
- HyperLinkField.cs
- CheckBoxStandardAdapter.cs
- ManagementOptions.cs
- GreenMethods.cs
- TypeBrowserDialog.cs
- RemotingConfigParser.cs
- CodeChecksumPragma.cs
- ImageButton.cs
- WebPartZoneBase.cs
- ResourceReferenceKeyNotFoundException.cs
- processwaithandle.cs
- TypeSystem.cs
- BitmapEffectDrawing.cs
- XmlSchemaObjectCollection.cs
- EntityContainer.cs
- WindowsRichEdit.cs
- Atom10FormatterFactory.cs
- SubpageParagraph.cs
- ExpandSegment.cs
- UdpTransportSettingsElement.cs
- Update.cs
- GuidelineSet.cs
- GridViewColumnHeaderAutomationPeer.cs
- ChildTable.cs
- Timeline.cs
- MergeFailedEvent.cs
- SqlInternalConnectionTds.cs
- CodeEntryPointMethod.cs
- SelectedCellsChangedEventArgs.cs
- SqlAggregateChecker.cs
- CollectionBase.cs
- CodeLabeledStatement.cs
- UrlParameterWriter.cs
- Debug.cs
- RegexNode.cs
- InvokeBase.cs
- VisualStateChangedEventArgs.cs
- WebBrowser.cs
- HwndSourceParameters.cs
- MasterPage.cs
- Int64AnimationBase.cs
- ToolStripDesignerAvailabilityAttribute.cs
- XPathDocumentBuilder.cs
- TemplatePropertyEntry.cs
- OperationCanceledException.cs
- BamlLocalizabilityResolver.cs
- AuthenticationConfig.cs
- DecoderBestFitFallback.cs
- DataGridViewRowCancelEventArgs.cs
- ToolboxComponentsCreatingEventArgs.cs
- IgnoreFlushAndCloseStream.cs
- ObjectDataSourceFilteringEventArgs.cs
- KeyedQueue.cs
- MachineKeySection.cs
- MetaTable.cs
- SqlDependencyListener.cs
- DataBindingExpressionBuilder.cs
- TreeViewCancelEvent.cs
- EmissiveMaterial.cs
- CqlGenerator.cs
- DatagridviewDisplayedBandsData.cs
- SecurityElement.cs
- PriorityQueue.cs
- HandleCollector.cs
- Brush.cs
- TrackingMemoryStream.cs
- DBCSCodePageEncoding.cs