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
- ClientFormsAuthenticationMembershipProvider.cs
- ServicePointManager.cs
- ToolTip.cs
- DataGridViewImageCell.cs
- SplitContainer.cs
- EntityViewGenerationAttribute.cs
- LocatorPartList.cs
- WaitForChangedResult.cs
- ProcessActivityTreeOptions.cs
- ReflectionServiceProvider.cs
- FormParameter.cs
- TreeViewAutomationPeer.cs
- VsPropertyGrid.cs
- TypeElement.cs
- DataGridColumnFloatingHeader.cs
- EventDescriptor.cs
- StorageEntityContainerMapping.cs
- EntityContainerEmitter.cs
- DecimalAnimation.cs
- ChannelManager.cs
- ZipIOLocalFileDataDescriptor.cs
- SourceLineInfo.cs
- ExceptionValidationRule.cs
- StoreItemCollection.cs
- BackgroundFormatInfo.cs
- DataGridDesigner.cs
- TextEndOfLine.cs
- followingquery.cs
- CodeGen.cs
- ControlCachePolicy.cs
- VisualStyleInformation.cs
- XmlSchemaObjectCollection.cs
- NGCPageContentCollectionSerializerAsync.cs
- RelativeSource.cs
- ComponentEditorForm.cs
- MessageDecoder.cs
- dataprotectionpermission.cs
- DateTimeOffsetStorage.cs
- SmtpNegotiateAuthenticationModule.cs
- SortDescription.cs
- PropertyChangedEventArgs.cs
- WmlListAdapter.cs
- TimelineGroup.cs
- InternalConfigConfigurationFactory.cs
- AspNetSynchronizationContext.cs
- ContractHandle.cs
- CharEnumerator.cs
- HtmlWindow.cs
- ToolStripItemRenderEventArgs.cs
- SQLMembershipProvider.cs
- ApplicationFileCodeDomTreeGenerator.cs
- AssociationSetMetadata.cs
- PrintDialog.cs
- WebBaseEventKeyComparer.cs
- BinaryVersion.cs
- MailDefinition.cs
- TextEffectResolver.cs
- WebPartDisplayModeCollection.cs
- EventWaitHandleSecurity.cs
- TextMessageEncoder.cs
- InternalDispatchObject.cs
- EntityViewGenerationAttribute.cs
- ProcessHostFactoryHelper.cs
- MiniMapControl.xaml.cs
- TextTrailingWordEllipsis.cs
- XmlAttributeOverrides.cs
- ToolStripItemGlyph.cs
- WindowsSpinner.cs
- ResXResourceReader.cs
- KeyedHashAlgorithm.cs
- StructuredTypeInfo.cs
- ListenerChannelContext.cs
- RemoteWebConfigurationHost.cs
- ContractNamespaceAttribute.cs
- VectorConverter.cs
- XmlMapping.cs
- AutoSizeToolBoxItem.cs
- KeyValuePair.cs
- StoreContentChangedEventArgs.cs
- ToolStripRenderer.cs
- CodeCastExpression.cs
- WorkflowTraceTransfer.cs
- QueryContinueDragEvent.cs
- ToolStripSeparator.cs
- SafeSecurityHelper.cs
- SqlSelectClauseBuilder.cs
- StringReader.cs
- userdatakeys.cs
- TextBreakpoint.cs
- BindingManagerDataErrorEventArgs.cs
- ApplicationActivator.cs
- ToolStripDropDown.cs
- SqlHelper.cs
- RelationshipNavigation.cs
- ContextQuery.cs
- CodeCompiler.cs
- sqlnorm.cs
- XmlCustomFormatter.cs
- StrokeRenderer.cs
- BigInt.cs