Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / MS / Internal / Utility / MonitorWrapper.cs / 1 / MonitorWrapper.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) 2005 by Microsoft Corporation. All rights reserved.
//
//
//
// Description: Wraps System.Threading.Monitor and adds a busy flag
//
//---------------------------------------------------------------------------
using System;
using System.Threading;
using System.Windows;
using MS.Internal;
namespace MS.Internal.Utility
{
///
/// Monitor with Busy flag while it is entered.
///
internal class MonitorWrapper
{
public IDisposable Enter()
{
Monitor.Enter(_syncRoot);
Interlocked.Increment(ref _enterCount);
return new MonitorHelper(this);
}
public void Exit()
{
int count = Interlocked.Decrement(ref _enterCount);
Invariant.Assert(count >= 0, "unmatched call to MonitorWrapper.Exit");
Monitor.Exit(_syncRoot);
}
public bool Busy
{
get
{
return (_enterCount > 0);
}
}
int _enterCount;
object _syncRoot = new object();
private class MonitorHelper : IDisposable
{
public MonitorHelper(MonitorWrapper monitorWrapper)
{
_monitorWrapper = monitorWrapper;
}
public void Dispose()
{
if (_monitorWrapper != null)
{
_monitorWrapper.Exit();
_monitorWrapper = null;
}
}
private MonitorWrapper _monitorWrapper;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) 2005 by Microsoft Corporation. All rights reserved.
//
//
//
// Description: Wraps System.Threading.Monitor and adds a busy flag
//
//---------------------------------------------------------------------------
using System;
using System.Threading;
using System.Windows;
using MS.Internal;
namespace MS.Internal.Utility
{
///
/// Monitor with Busy flag while it is entered.
///
internal class MonitorWrapper
{
public IDisposable Enter()
{
Monitor.Enter(_syncRoot);
Interlocked.Increment(ref _enterCount);
return new MonitorHelper(this);
}
public void Exit()
{
int count = Interlocked.Decrement(ref _enterCount);
Invariant.Assert(count >= 0, "unmatched call to MonitorWrapper.Exit");
Monitor.Exit(_syncRoot);
}
public bool Busy
{
get
{
return (_enterCount > 0);
}
}
int _enterCount;
object _syncRoot = new object();
private class MonitorHelper : IDisposable
{
public MonitorHelper(MonitorWrapper monitorWrapper)
{
_monitorWrapper = monitorWrapper;
}
public void Dispose()
{
if (_monitorWrapper != null)
{
_monitorWrapper.Exit();
_monitorWrapper = null;
}
}
private MonitorWrapper _monitorWrapper;
}
}
}
// 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
- SqlNotificationRequest.cs
- DbConnectionOptions.cs
- ScriptResourceInfo.cs
- TrackingProfile.cs
- MDIWindowDialog.cs
- FormatException.cs
- WorkerRequest.cs
- UriTemplate.cs
- DataTablePropertyDescriptor.cs
- GradientStopCollection.cs
- ProfileParameter.cs
- MetadataArtifactLoaderCompositeResource.cs
- IISMapPath.cs
- FlagsAttribute.cs
- UpdateTranslator.cs
- hwndwrapper.cs
- ContentPropertyAttribute.cs
- DocumentPaginator.cs
- FontSizeConverter.cs
- FrameworkReadOnlyPropertyMetadata.cs
- LocalBuilder.cs
- ListViewPagedDataSource.cs
- SymLanguageType.cs
- xml.cs
- DataGridViewCellPaintingEventArgs.cs
- PageWrapper.cs
- TdsParserSafeHandles.cs
- TypeDescriptionProviderAttribute.cs
- CommandDevice.cs
- UniformGrid.cs
- HWStack.cs
- IncomingWebRequestContext.cs
- DecoratedNameAttribute.cs
- RequestQueue.cs
- ObjectDataSource.cs
- EndCreateSecurityTokenRequest.cs
- SerTrace.cs
- ScriptingProfileServiceSection.cs
- HtmlInputControl.cs
- ImageListImageEditor.cs
- CodeDelegateInvokeExpression.cs
- ObservableCollection.cs
- SqlDelegatedTransaction.cs
- PropertyEmitter.cs
- SelectionService.cs
- AliasGenerator.cs
- Effect.cs
- ISAPIApplicationHost.cs
- QilTernary.cs
- DataServicePagingProviderWrapper.cs
- TextDecorationCollection.cs
- ComponentCollection.cs
- SourceInterpreter.cs
- EditorPartChrome.cs
- ProfileEventArgs.cs
- AccessDataSource.cs
- FolderLevelBuildProviderCollection.cs
- Border.cs
- SqlCacheDependencySection.cs
- OdbcConnection.cs
- BuildProviderAppliesToAttribute.cs
- WinFormsSpinner.cs
- BevelBitmapEffect.cs
- ListenDesigner.cs
- KnownBoxes.cs
- DetailsViewRow.cs
- TableRow.cs
- WebColorConverter.cs
- GenericQueueSurrogate.cs
- SqlUserDefinedAggregateAttribute.cs
- CompositeFontParser.cs
- UnsafeNativeMethods.cs
- SoapAttributes.cs
- ProxyGenerationError.cs
- TreeViewItemAutomationPeer.cs
- UrlPath.cs
- GroupBoxRenderer.cs
- SingleAnimationUsingKeyFrames.cs
- MenuAdapter.cs
- ListViewInsertedEventArgs.cs
- ResXDataNode.cs
- WindowsFont.cs
- ExternalException.cs
- SiteMembershipCondition.cs
- PkcsMisc.cs
- Marshal.cs
- RealizationContext.cs
- QilParameter.cs
- FileSystemWatcher.cs
- AsyncPostBackTrigger.cs
- ArrayExtension.cs
- ProjectionCamera.cs
- DataRelationPropertyDescriptor.cs
- AttachedPropertyMethodSelector.cs
- UriSection.cs
- ParameterToken.cs
- Exceptions.cs
- ImageSourceValueSerializer.cs
- RtType.cs
- InfiniteIntConverter.cs