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 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DiagnosticTraceSource.cs
- ApplyHostConfigurationBehavior.cs
- ProfessionalColorTable.cs
- BinHexDecoder.cs
- _LazyAsyncResult.cs
- HandleDictionary.cs
- EntityParameter.cs
- XsltConvert.cs
- ObjectReaderCompiler.cs
- ObjectHandle.cs
- TextDecorationUnitValidation.cs
- ToolboxItemImageConverter.cs
- ExtendLockAsyncResult.cs
- COMException.cs
- PropertyChangedEventArgs.cs
- HtmlInputImage.cs
- ImageBrush.cs
- BamlBinaryWriter.cs
- HtmlInputHidden.cs
- ServiceDiscoveryElement.cs
- Frame.cs
- PowerStatus.cs
- PointHitTestResult.cs
- XmlWrappingReader.cs
- AtomMaterializerLog.cs
- MessagePropertyVariants.cs
- wgx_commands.cs
- EditorPart.cs
- DocumentReference.cs
- SQLSingle.cs
- TCPClient.cs
- TcpTransportSecurityElement.cs
- BooleanConverter.cs
- DefaultEventAttribute.cs
- Transform3DGroup.cs
- CookieProtection.cs
- Repeater.cs
- ReferencedType.cs
- Brush.cs
- Italic.cs
- TypedColumnHandler.cs
- MessageSecurityOverMsmqElement.cs
- NativeObjectSecurity.cs
- StreamAsIStream.cs
- TypedRowGenerator.cs
- ValidationPropertyAttribute.cs
- TitleStyle.cs
- CmsInterop.cs
- VerticalAlignConverter.cs
- DataGridTableCollection.cs
- EntityRecordInfo.cs
- ReferenceEqualityComparer.cs
- MatrixKeyFrameCollection.cs
- TextEffect.cs
- SEHException.cs
- XmlSchemaFacet.cs
- CustomAttributeBuilder.cs
- WizardStepBase.cs
- ConfigXmlText.cs
- SelectedPathEditor.cs
- UserControlParser.cs
- ToolStripContainerActionList.cs
- OpacityConverter.cs
- TemplatePropertyEntry.cs
- UpdateException.cs
- BitmapImage.cs
- NativeMethods.cs
- Odbc32.cs
- DesignerAttribute.cs
- CalendarDay.cs
- DataTableNewRowEvent.cs
- IgnoreFlushAndCloseStream.cs
- StringOutput.cs
- PublisherMembershipCondition.cs
- DataGridViewSelectedCellCollection.cs
- InputBindingCollection.cs
- AlternationConverter.cs
- SimpleBitVector32.cs
- BooleanConverter.cs
- CodeAttachEventStatement.cs
- PasswordBox.cs
- unsafenativemethodsother.cs
- SoapExtensionTypeElement.cs
- UserControlCodeDomTreeGenerator.cs
- WebPartVerb.cs
- HttpValueCollection.cs
- CrossContextChannel.cs
- SubtreeProcessor.cs
- MessageEncoder.cs
- HijriCalendar.cs
- WorkflowQueue.cs
- RelationshipEndCollection.cs
- ToolStripDropDownMenu.cs
- SapiRecognizer.cs
- QuaternionAnimationBase.cs
- Light.cs
- Selection.cs
- OrderedDictionary.cs
- ConnectionStringSettings.cs
- CountdownEvent.cs