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
- invalidudtexception.cs
- HMACSHA256.cs
- OdbcEnvironmentHandle.cs
- FolderBrowserDialog.cs
- CorePropertiesFilter.cs
- IntPtr.cs
- OuterGlowBitmapEffect.cs
- StylusShape.cs
- CodeTypeReference.cs
- XmlQueryCardinality.cs
- DocumentViewerConstants.cs
- DoWorkEventArgs.cs
- SqlSupersetValidator.cs
- parserscommon.cs
- PointLightBase.cs
- GradientStop.cs
- XmlDocument.cs
- SecureStringHasher.cs
- DrawingContext.cs
- FixedPageAutomationPeer.cs
- ContentElementCollection.cs
- DataControlButton.cs
- PermissionSetTriple.cs
- SelectionItemPattern.cs
- UIPermission.cs
- DecoderNLS.cs
- HttpChannelHelpers.cs
- RequestStatusBarUpdateEventArgs.cs
- RelationHandler.cs
- ChangesetResponse.cs
- ErrorFormatter.cs
- Assert.cs
- BinaryObjectWriter.cs
- Rfc2898DeriveBytes.cs
- SafeFileHandle.cs
- LinqDataSource.cs
- MasterPageBuildProvider.cs
- SqlProcedureAttribute.cs
- DesignerActionUI.cs
- WebPartDescription.cs
- Signature.cs
- MailDefinition.cs
- DeferredTextReference.cs
- XmlWrappingReader.cs
- SecurityUniqueId.cs
- PropertyGeneratedEventArgs.cs
- IisTraceWebEventProvider.cs
- PreviewControlDesigner.cs
- SqlReferenceCollection.cs
- FragmentNavigationEventArgs.cs
- TdsParserHelperClasses.cs
- SequenceFullException.cs
- VectorKeyFrameCollection.cs
- ColorAnimationBase.cs
- RequestTimeoutManager.cs
- TableStyle.cs
- mansign.cs
- AcceleratedTokenProvider.cs
- X509CertificateInitiatorServiceCredential.cs
- CqlBlock.cs
- FixedSOMTableCell.cs
- FacetDescription.cs
- IDReferencePropertyAttribute.cs
- IdentityNotMappedException.cs
- FormViewCommandEventArgs.cs
- CodeTypeReference.cs
- ValidatingPropertiesEventArgs.cs
- MarkedHighlightComponent.cs
- DataGridViewComboBoxColumn.cs
- BaseDataList.cs
- COM2Enum.cs
- TextElementEnumerator.cs
- ComContractElementCollection.cs
- TreeNodeCollectionEditorDialog.cs
- StatusStrip.cs
- StaticFileHandler.cs
- CryptoApi.cs
- Wizard.cs
- OdbcEnvironment.cs
- PerformanceCounter.cs
- GroupDescription.cs
- DataGridViewCellPaintingEventArgs.cs
- SchemaTableOptionalColumn.cs
- InstallerTypeAttribute.cs
- HtmlLabelAdapter.cs
- PaperSource.cs
- SoapInteropTypes.cs
- TextSpan.cs
- CapabilitiesPattern.cs
- XmlSchemaInferenceException.cs
- MethodImplAttribute.cs
- SqlCachedBuffer.cs
- CachingHintValidation.cs
- DesignerUtils.cs
- PropertyChangedEventArgs.cs
- TreeViewHitTestInfo.cs
- SamlSubjectStatement.cs
- GroupBoxRenderer.cs
- XmlSchemaFacet.cs
- RequestQueue.cs