Code:
/ 4.0 / 4.0 / 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. 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
- NotSupportedException.cs
- DbParameterHelper.cs
- WizardPanelChangingEventArgs.cs
- MarshalByRefObject.cs
- NavigationWindowAutomationPeer.cs
- WCFModelStrings.Designer.cs
- BaseCAMarshaler.cs
- UnmanagedMemoryStreamWrapper.cs
- QuestionEventArgs.cs
- WebPartsPersonalizationAuthorization.cs
- XmlSchemaFacet.cs
- EventLog.cs
- JsonFormatGeneratorStatics.cs
- TdsParser.cs
- ErrorStyle.cs
- SByte.cs
- TaskSchedulerException.cs
- TextDecorationCollectionConverter.cs
- DataAdapter.cs
- PlatformNotSupportedException.cs
- RoleService.cs
- PolyBezierSegment.cs
- LayoutInformation.cs
- ListViewTableRow.cs
- TextSelection.cs
- BindingCompleteEventArgs.cs
- MultipleViewPattern.cs
- ObjectKeyFrameCollection.cs
- ArraySortHelper.cs
- ParameterElement.cs
- RuntimeHelpers.cs
- DocumentGridPage.cs
- TypeSystem.cs
- Point4D.cs
- DocumentSequenceHighlightLayer.cs
- PixelFormat.cs
- Light.cs
- AbandonedMutexException.cs
- GC.cs
- XPathNodeIterator.cs
- NetStream.cs
- ComplexObject.cs
- ExpressionBuilder.cs
- TextFormatterHost.cs
- UnionCqlBlock.cs
- SmiRecordBuffer.cs
- ServiceProviders.cs
- SiteMapNodeItem.cs
- ColumnMapTranslator.cs
- ServiceObjectContainer.cs
- SmiEventSink_Default.cs
- GlobalItem.cs
- EventWaitHandleSecurity.cs
- CaretElement.cs
- MouseEvent.cs
- SecurityContextSecurityTokenParameters.cs
- DefaultSection.cs
- SafeNativeMethods.cs
- BinaryMessageEncoder.cs
- CanonicalXml.cs
- MethodToken.cs
- CodeMemberField.cs
- coordinator.cs
- _TransmitFileOverlappedAsyncResult.cs
- ZipIOModeEnforcingStream.cs
- CompositeFontParser.cs
- sqlpipe.cs
- coordinator.cs
- HttpWebRequest.cs
- ActivationServices.cs
- JoinGraph.cs
- WebMessageEncodingBindingElement.cs
- ObjectDataSourceDisposingEventArgs.cs
- ProjectedWrapper.cs
- cookie.cs
- EntityUtil.cs
- FixedSOMFixedBlock.cs
- StsCommunicationException.cs
- MetadataUtil.cs
- SemaphoreSecurity.cs
- DataGridItemCollection.cs
- DataPagerFieldCollection.cs
- RunInstallerAttribute.cs
- ClockGroup.cs
- ReadOnlyCollection.cs
- SettingsPropertyValueCollection.cs
- ToolStripSplitStackLayout.cs
- DebugHandleTracker.cs
- ParallelActivityDesigner.cs
- DependencyObjectType.cs
- PrintDialogException.cs
- PasswordPropertyTextAttribute.cs
- SafePEFileHandle.cs
- TextSpanModifier.cs
- InfoCardBaseException.cs
- TreeView.cs
- CodeAttachEventStatement.cs
- HMACSHA1.cs
- CapacityStreamGeometryContext.cs
- CompilerScopeManager.cs