Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Shared / MS / Internal / ReaderWriterLockWrapper.cs / 1 / ReaderWriterLockWrapper.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // Wrapper that allows a ReaderWriterLock to work with C#'s using() clause // // History: // 07/23/2003 : BrendanM Ported to WCP // //--------------------------------------------------------------------------- using System; using System.Threading; using MS.Internal.WindowsBase; namespace MS.Internal { // Wrapper that allows a ReaderWriterLock to work with C#'s using() clause [FriendAccessAllowed] // Built into Base, used by Core and Framework. internal class ReaderWriterLockWrapper { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors internal ReaderWriterLockWrapper() { _rwLock = new ReaderWriterLock(); _awr = new AutoWriterRelease(_rwLock); _arr = new AutoReaderRelease(_rwLock); } #endregion Constructors //------------------------------------------------------ // // Internal Properties // //----------------------------------------------------- #region Internal Properties internal IDisposable WriteLock { get { _rwLock.AcquireWriterLock(Timeout.Infinite); return _awr; } } internal IDisposable ReadLock { get { _rwLock.AcquireReaderLock(Timeout.Infinite); return _arr; } } #endregion Internal Properties //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ #region Private Fields private ReaderWriterLock _rwLock; private AutoReaderRelease _arr; private AutoWriterRelease _awr; #endregion Private Fields //----------------------------------------------------- // // Private Classes & Structs // //------------------------------------------------------ #region Private Classes & Structs private struct AutoWriterRelease : IDisposable { public AutoWriterRelease(ReaderWriterLock rwLock) { _lock = rwLock; } public void Dispose() { _lock.ReleaseWriterLock(); } private ReaderWriterLock _lock; } private struct AutoReaderRelease : IDisposable { public AutoReaderRelease(ReaderWriterLock rwLock) { _lock = rwLock; } public void Dispose() { _lock.ReleaseReaderLock(); } private ReaderWriterLock _lock; } #endregion Private Classes } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // Wrapper that allows a ReaderWriterLock to work with C#'s using() clause // // History: // 07/23/2003 : BrendanM Ported to WCP // //--------------------------------------------------------------------------- using System; using System.Threading; using MS.Internal.WindowsBase; namespace MS.Internal { // Wrapper that allows a ReaderWriterLock to work with C#'s using() clause [FriendAccessAllowed] // Built into Base, used by Core and Framework. internal class ReaderWriterLockWrapper { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors internal ReaderWriterLockWrapper() { _rwLock = new ReaderWriterLock(); _awr = new AutoWriterRelease(_rwLock); _arr = new AutoReaderRelease(_rwLock); } #endregion Constructors //------------------------------------------------------ // // Internal Properties // //----------------------------------------------------- #region Internal Properties internal IDisposable WriteLock { get { _rwLock.AcquireWriterLock(Timeout.Infinite); return _awr; } } internal IDisposable ReadLock { get { _rwLock.AcquireReaderLock(Timeout.Infinite); return _arr; } } #endregion Internal Properties //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ #region Private Fields private ReaderWriterLock _rwLock; private AutoReaderRelease _arr; private AutoWriterRelease _awr; #endregion Private Fields //----------------------------------------------------- // // Private Classes & Structs // //------------------------------------------------------ #region Private Classes & Structs private struct AutoWriterRelease : IDisposable { public AutoWriterRelease(ReaderWriterLock rwLock) { _lock = rwLock; } public void Dispose() { _lock.ReleaseWriterLock(); } private ReaderWriterLock _lock; } private struct AutoReaderRelease : IDisposable { public AutoReaderRelease(ReaderWriterLock rwLock) { _lock = rwLock; } public void Dispose() { _lock.ReleaseReaderLock(); } private ReaderWriterLock _lock; } #endregion Private Classes } } // 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
- ClientBuildManager.cs
- ExecutionEngineException.cs
- LocalizationParserHooks.cs
- Size3D.cs
- PlatformNotSupportedException.cs
- TriggerCollection.cs
- PageParser.cs
- SmtpDigestAuthenticationModule.cs
- XmlCompatibilityReader.cs
- FilePrompt.cs
- ResourceDescriptionAttribute.cs
- UdpSocketReceiveManager.cs
- KeyValueConfigurationElement.cs
- FontStyleConverter.cs
- WSDualHttpBinding.cs
- Block.cs
- SmiMetaData.cs
- safex509handles.cs
- Image.cs
- DataGridViewTextBoxEditingControl.cs
- StreamInfo.cs
- EventSinkHelperWriter.cs
- Int64Converter.cs
- TextServicesLoader.cs
- DictionaryBase.cs
- MSAANativeProvider.cs
- DefaultPrintController.cs
- TemplateColumn.cs
- ParserContext.cs
- DoubleAnimationUsingKeyFrames.cs
- WindowCollection.cs
- RenderData.cs
- RoleBoolean.cs
- OneWayBindingElementImporter.cs
- CultureTableRecord.cs
- FieldAccessException.cs
- IndexedEnumerable.cs
- ControlEvent.cs
- CodeComment.cs
- MutexSecurity.cs
- DataGridToolTip.cs
- EventDescriptor.cs
- DbConnectionInternal.cs
- ToolBarButton.cs
- Speller.cs
- XmlNodeReader.cs
- Ref.cs
- SoapFault.cs
- ByteAnimationBase.cs
- GenericPrincipal.cs
- CroppedBitmap.cs
- Columns.cs
- DataGridViewEditingControlShowingEventArgs.cs
- ProcessHostServerConfig.cs
- WebOperationContext.cs
- ToolboxComponentsCreatedEventArgs.cs
- OrderedDictionary.cs
- TemplatedEditableDesignerRegion.cs
- ExpressionBindingCollection.cs
- BeginCreateSecurityTokenRequest.cs
- DataGridViewAdvancedBorderStyle.cs
- TriggerBase.cs
- SecurityTokenException.cs
- HtmlWindowCollection.cs
- TextElement.cs
- XmlNamedNodeMap.cs
- TypeLibConverter.cs
- FileDialogPermission.cs
- BinaryReader.cs
- ViewLoader.cs
- EdmComplexPropertyAttribute.cs
- uribuilder.cs
- EntityStoreSchemaGenerator.cs
- BoundConstants.cs
- ExtensibleSyndicationObject.cs
- CommandHelper.cs
- PathFigureCollection.cs
- ColorConverter.cs
- SoundPlayerAction.cs
- SettingsBindableAttribute.cs
- HwndHost.cs
- ManagementPath.cs
- PropertyAccessVisitor.cs
- DataGridViewCellStyleChangedEventArgs.cs
- TokenBasedSet.cs
- ReaderWriterLockSlim.cs
- EmptyTextWriter.cs
- VisualBrush.cs
- CacheEntry.cs
- ProviderException.cs
- HttpHandlerAction.cs
- XmlChildEnumerator.cs
- ExpressionBinding.cs
- TypeAccessException.cs
- ButtonAutomationPeer.cs
- KeyboardNavigation.cs
- FixedSchema.cs
- CompilerCollection.cs
- ScriptRef.cs
- SystemTcpConnection.cs