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
- VisualTreeHelper.cs
- HuffmanTree.cs
- ContentAlignmentEditor.cs
- LinearGradientBrush.cs
- SoapRpcMethodAttribute.cs
- MonthChangedEventArgs.cs
- NextPreviousPagerField.cs
- DeviceContext.cs
- HashCodeCombiner.cs
- ListBase.cs
- CallbackTimeoutsBehavior.cs
- ZoomPercentageConverter.cs
- OpenTypeLayoutCache.cs
- AdornerPresentationContext.cs
- _HelperAsyncResults.cs
- WebContext.cs
- Comparer.cs
- ExpandCollapseProviderWrapper.cs
- HtmlTableRow.cs
- TaskDesigner.cs
- ClientRolePrincipal.cs
- ActiveXSite.cs
- XmlLanguageConverter.cs
- TextBoxAutoCompleteSourceConverter.cs
- BaseInfoTable.cs
- DesignTimeTemplateParser.cs
- PropertyCollection.cs
- TcpSocketManager.cs
- FormViewDeleteEventArgs.cs
- EdmComplexTypeAttribute.cs
- OperandQuery.cs
- ToolboxComponentsCreatedEventArgs.cs
- BuildResultCache.cs
- TdsParserSafeHandles.cs
- ValueUnavailableException.cs
- ObjectCloneHelper.cs
- DataGridColumnHeader.cs
- SignatureTargetIdManager.cs
- NumericUpDown.cs
- BindingList.cs
- MapPathBasedVirtualPathProvider.cs
- Number.cs
- CodeTypeParameter.cs
- ContentDefinition.cs
- DataGridViewCellValidatingEventArgs.cs
- FileChangesMonitor.cs
- BuiltInExpr.cs
- UnsafeNativeMethods.cs
- Pair.cs
- SelectionChangedEventArgs.cs
- MediaTimeline.cs
- RawAppCommandInputReport.cs
- TextComposition.cs
- Scripts.cs
- EventHandlers.cs
- FilterQueryOptionExpression.cs
- HtmlTernaryTree.cs
- XmlWellformedWriter.cs
- HotCommands.cs
- SerialPinChanges.cs
- PrintDocument.cs
- ConfigurationLocationCollection.cs
- InteropBitmapSource.cs
- OracleMonthSpan.cs
- NameValueCollection.cs
- Container.cs
- NativeObjectSecurity.cs
- SystemResourceHost.cs
- AccessDataSource.cs
- ServiceRoute.cs
- AuthenticatedStream.cs
- DrawingContext.cs
- URLAttribute.cs
- ContentValidator.cs
- EnumValidator.cs
- XmlReader.cs
- FontFamilyIdentifier.cs
- ProcessModule.cs
- SynchronizingStream.cs
- AxHostDesigner.cs
- versioninfo.cs
- LicenseManager.cs
- ProjectionPruner.cs
- TextTreeRootNode.cs
- ReferenceConverter.cs
- OutgoingWebRequestContext.cs
- ComponentCodeDomSerializer.cs
- WmfPlaceableFileHeader.cs
- AuthorizationSection.cs
- SqlBulkCopyColumnMappingCollection.cs
- UICuesEvent.cs
- UdpTransportSettingsElement.cs
- TransactionException.cs
- AliasedSlot.cs
- ValidatorCollection.cs
- CodeArgumentReferenceExpression.cs
- TimerElapsedEvenArgs.cs
- XmlDownloadManager.cs
- Classification.cs
- PathFigure.cs