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
- DBAsyncResult.cs
- FactoryMaker.cs
- GenericWebPart.cs
- COM2ComponentEditor.cs
- ScriptManager.cs
- ProviderCommandInfoUtils.cs
- TdsEnums.cs
- PersistenceTask.cs
- ControlDesignerState.cs
- EdmItemError.cs
- IndexedString.cs
- SmtpReplyReader.cs
- ConfigurationElementProperty.cs
- FastPropertyAccessor.cs
- DependencyPropertyKey.cs
- XamlNamespaceHelper.cs
- HttpResponseHeader.cs
- DefaultAsyncDataDispatcher.cs
- IdentitySection.cs
- ChtmlTextWriter.cs
- HttpClientChannel.cs
- InsufficientExecutionStackException.cs
- FixedPageProcessor.cs
- VirtualPathProvider.cs
- MultiSelector.cs
- MenuStrip.cs
- ApplicationSecurityInfo.cs
- Vector3D.cs
- Operand.cs
- IntSecurity.cs
- TaskExceptionHolder.cs
- EntityDataSourceContainerNameItem.cs
- IisTraceListener.cs
- BamlCollectionHolder.cs
- FontCacheUtil.cs
- BrowserCapabilitiesCompiler.cs
- ShaderEffect.cs
- EventLogWatcher.cs
- XmlTextEncoder.cs
- DbProviderConfigurationHandler.cs
- WebPartConnection.cs
- GeometryHitTestResult.cs
- VsPropertyGrid.cs
- CqlErrorHelper.cs
- SimpleHandlerBuildProvider.cs
- BitSet.cs
- Matrix.cs
- CodeParameterDeclarationExpression.cs
- UnicastIPAddressInformationCollection.cs
- PreviewControlDesigner.cs
- AuthStoreRoleProvider.cs
- IdnElement.cs
- FontClient.cs
- AccessText.cs
- PreloadHost.cs
- GorillaCodec.cs
- TextCollapsingProperties.cs
- CalendarDay.cs
- WebPartMovingEventArgs.cs
- UnknownWrapper.cs
- ModelFactory.cs
- XmlSchemaAnnotation.cs
- CodeNamespaceImport.cs
- ConstraintCollection.cs
- webeventbuffer.cs
- ScrollProviderWrapper.cs
- Label.cs
- KnownColorTable.cs
- WebBrowserNavigatedEventHandler.cs
- tabpagecollectioneditor.cs
- XmlCDATASection.cs
- PolyQuadraticBezierSegment.cs
- userdatakeys.cs
- _DomainName.cs
- SectionVisual.cs
- WebPart.cs
- DataViewManager.cs
- XmlCharType.cs
- MissingFieldException.cs
- ModuleBuilderData.cs
- DesignDataSource.cs
- NativeMethods.cs
- DateTimeOffsetConverter.cs
- MessageBodyMemberAttribute.cs
- RoleManagerModule.cs
- GeneratedContractType.cs
- PagePropertiesChangingEventArgs.cs
- SafeRightsManagementEnvironmentHandle.cs
- WorkflowMessageEventArgs.cs
- tooltip.cs
- ThemeInfoAttribute.cs
- TextDecorations.cs
- RuleSettingsCollection.cs
- HandlerBase.cs
- AsyncContentLoadedEventArgs.cs
- WSFederationHttpBindingElement.cs
- TextAction.cs
- AnyAllSearchOperator.cs
- NgenServicingAttributes.cs
- DataKeyArray.cs