Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Shared / MS / Internal / ReaderWriterLockWrapper.cs / 1305600 / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- _SSPIWrapper.cs
- PathStreamGeometryContext.cs
- NotConverter.cs
- AssemblyUtil.cs
- DataGridViewIntLinkedList.cs
- Compilation.cs
- DataStreams.cs
- XhtmlStyleClass.cs
- ContextQuery.cs
- TreeNodeSelectionProcessor.cs
- WSFederationHttpBindingCollectionElement.cs
- QueryStringHandler.cs
- EdmItemCollection.cs
- RecognizedWordUnit.cs
- CodeCompiler.cs
- RegionInfo.cs
- ChooseAction.cs
- XmlObjectSerializerWriteContextComplex.cs
- GridEntry.cs
- DbConnectionOptions.cs
- GAC.cs
- TypedOperationInfo.cs
- GroupLabel.cs
- DocumentApplicationJournalEntry.cs
- AssociationSetMetadata.cs
- XamlReaderHelper.cs
- DataExpression.cs
- ConstructorNeedsTagAttribute.cs
- TableLayoutPanel.cs
- ProcessThreadDesigner.cs
- DateTimeStorage.cs
- AsyncWaitHandle.cs
- GraphicsPath.cs
- HostVisual.cs
- StoreAnnotationsMap.cs
- TableLayoutPanelDesigner.cs
- ColumnResizeUndoUnit.cs
- Panel.cs
- ServiceModelDictionary.cs
- ListViewUpdatedEventArgs.cs
- linebase.cs
- FormsAuthenticationEventArgs.cs
- ServiceInstallComponent.cs
- ToolboxComponentsCreatingEventArgs.cs
- DataGridViewColumnTypePicker.cs
- SafeHandle.cs
- TableAdapterManagerNameHandler.cs
- versioninfo.cs
- validationstate.cs
- SafeViewOfFileHandle.cs
- ExcCanonicalXml.cs
- WebControlAdapter.cs
- PromptStyle.cs
- XmlReflectionImporter.cs
- Size3DConverter.cs
- Internal.cs
- Timer.cs
- XamlPointCollectionSerializer.cs
- TypeSemantics.cs
- TypedReference.cs
- TransformCollection.cs
- DiscoveryVersion.cs
- BinaryReader.cs
- BitmapPalettes.cs
- Utilities.cs
- XmlNavigatorFilter.cs
- TableCellCollection.cs
- CacheHelper.cs
- NamespaceInfo.cs
- FormsAuthenticationCredentials.cs
- OrderedDictionary.cs
- HostedHttpContext.cs
- OneWayChannelFactory.cs
- CodeGenerator.cs
- DecoderFallback.cs
- AssemblyBuilder.cs
- SingleAnimationBase.cs
- _NtlmClient.cs
- SrgsSubset.cs
- DocumentAutomationPeer.cs
- ClientFormsIdentity.cs
- StylusButton.cs
- MsmqElementBase.cs
- ObsoleteAttribute.cs
- FontNamesConverter.cs
- TableLayout.cs
- IgnorePropertiesAttribute.cs
- HttpVersion.cs
- EnumerableRowCollection.cs
- InheritanceContextChangedEventManager.cs
- Helper.cs
- ObjectDataSourceDisposingEventArgs.cs
- PropertyValue.cs
- RangeValuePatternIdentifiers.cs
- SqlDataSourceQuery.cs
- HtmlElementEventArgs.cs
- HttpServerUtilityBase.cs
- PrtTicket_Public.cs
- DecimalKeyFrameCollection.cs
- Base64Encoder.cs