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
- ReferenceConverter.cs
- ArrayElementGridEntry.cs
- SqlDependencyListener.cs
- HttpCapabilitiesBase.cs
- BindToObject.cs
- CachingHintValidation.cs
- IgnoreSectionHandler.cs
- FormViewRow.cs
- ExpressionDumper.cs
- HttpFileCollection.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- CacheDependency.cs
- PixelFormat.cs
- ResourceType.cs
- Slider.cs
- ContentType.cs
- TcpClientChannel.cs
- WindowsFormsHelpers.cs
- FaultFormatter.cs
- XmlDataDocument.cs
- dtdvalidator.cs
- CardSpaceShim.cs
- SettingsPropertyWrongTypeException.cs
- EncryptedReference.cs
- TreeNodeBinding.cs
- BitmapEffectGroup.cs
- PageCodeDomTreeGenerator.cs
- RemoteCryptoSignHashRequest.cs
- ExternalDataExchangeService.cs
- SamlSerializer.cs
- Material.cs
- EnumerableRowCollectionExtensions.cs
- EventEntry.cs
- ObjectAnimationBase.cs
- StorageEntitySetMapping.cs
- ToolStripGripRenderEventArgs.cs
- PathNode.cs
- DataGridParentRows.cs
- FunctionImportMapping.cs
- XPathNavigatorReader.cs
- RuntimeArgument.cs
- ListItemsCollectionEditor.cs
- ActivityValidationServices.cs
- GridSplitterAutomationPeer.cs
- _ShellExpression.cs
- ArrayWithOffset.cs
- TimeSpanValidator.cs
- ToolStripOverflowButton.cs
- CommandValueSerializer.cs
- HandleCollector.cs
- HtmlElementErrorEventArgs.cs
- NotificationContext.cs
- Win32KeyboardDevice.cs
- Helper.cs
- AttachmentService.cs
- ScaleTransform.cs
- Ref.cs
- LiteralControl.cs
- QuotedStringWriteStateInfo.cs
- WhitespaceSignificantCollectionAttribute.cs
- RectAnimationClockResource.cs
- OracleCommand.cs
- MobileControlPersister.cs
- TransactionScope.cs
- SizeAnimationBase.cs
- SessionStateContainer.cs
- Margins.cs
- ChangeDirector.cs
- LedgerEntryCollection.cs
- PointConverter.cs
- ColorDialog.cs
- HtmlLink.cs
- DeviceFilterEditorDialog.cs
- PropertyInformation.cs
- _LocalDataStoreMgr.cs
- CalendarTable.cs
- SqlProfileProvider.cs
- NaturalLanguageHyphenator.cs
- TypeConverterHelper.cs
- SourceFileBuildProvider.cs
- ConfigurationManager.cs
- PenContexts.cs
- BasicExpandProvider.cs
- ExceptionUtil.cs
- LassoHelper.cs
- CompiledRegexRunner.cs
- StyleConverter.cs
- LazyTextWriterCreator.cs
- EncodingStreamWrapper.cs
- Form.cs
- KeyValuePairs.cs
- CapiSafeHandles.cs
- Convert.cs
- TimeZone.cs
- PageThemeBuildProvider.cs
- SharedDp.cs
- ProgressBar.cs
- CaseInsensitiveOrdinalStringComparer.cs
- PrivateFontCollection.cs
- ProtocolViolationException.cs