Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- ResourceDescriptionAttribute.cs
- RectAnimationBase.cs
- SoapParser.cs
- AppSettingsExpressionBuilder.cs
- DataView.cs
- LinkedDataMemberFieldEditor.cs
- SafePointer.cs
- DataGridSortCommandEventArgs.cs
- ResolveMatchesCD1.cs
- SafeEventLogWriteHandle.cs
- PrincipalPermission.cs
- MenuItem.cs
- DataRelationPropertyDescriptor.cs
- BoundColumn.cs
- HtmlInputPassword.cs
- SpellCheck.cs
- CategoryState.cs
- OrderedDictionaryStateHelper.cs
- TransformDescriptor.cs
- OdbcUtils.cs
- XamlInt32CollectionSerializer.cs
- SudsParser.cs
- ActivatableWorkflowsQueryResult.cs
- XmlValueConverter.cs
- SinglePageViewer.cs
- WebPartPersonalization.cs
- UpdateTracker.cs
- CfgRule.cs
- Point3D.cs
- EncoderNLS.cs
- SizeAnimationBase.cs
- TextDocumentView.cs
- CultureSpecificStringDictionary.cs
- FreezableDefaultValueFactory.cs
- EventMappingSettings.cs
- MultiView.cs
- TemplateBaseAction.cs
- AstTree.cs
- WebBrowserNavigatedEventHandler.cs
- DataControlField.cs
- AnnotationAuthorChangedEventArgs.cs
- RegisteredScript.cs
- ClientFormsIdentity.cs
- SafeNativeMethods.cs
- SrgsElementFactory.cs
- MdiWindowListItemConverter.cs
- CollectionViewGroup.cs
- EditorZoneBase.cs
- ToolboxDataAttribute.cs
- UIPermission.cs
- ServiceInstallComponent.cs
- MarshalByRefObject.cs
- TableRow.cs
- DataShape.cs
- XMLSchema.cs
- CurrentChangingEventManager.cs
- PerformanceCounterLib.cs
- ChameleonKey.cs
- ListViewItemCollectionEditor.cs
- XPathParser.cs
- WindowsFormsHost.cs
- RowVisual.cs
- RandomNumberGenerator.cs
- HtmlInputCheckBox.cs
- LogLogRecordHeader.cs
- WebPartsPersonalizationAuthorization.cs
- DbFunctionCommandTree.cs
- TextParagraph.cs
- RSATokenProvider.cs
- ParameterCollection.cs
- StringValidator.cs
- DataGridViewCellFormattingEventArgs.cs
- SecUtil.cs
- HtmlEmptyTagControlBuilder.cs
- WrappedReader.cs
- EqualityArray.cs
- ImageDesigner.cs
- XamlToRtfWriter.cs
- BoolLiteral.cs
- JapaneseCalendar.cs
- BitmapPalette.cs
- ScaleTransform3D.cs
- Atom10FormatterFactory.cs
- BinaryMethodMessage.cs
- XmlNodeChangedEventManager.cs
- EllipseGeometry.cs
- StreamWriter.cs
- ClientSection.cs
- Misc.cs
- ConfigXmlSignificantWhitespace.cs
- XmlDsigSep2000.cs
- Int16AnimationUsingKeyFrames.cs
- ToolStripDropDownButton.cs
- PartialCachingAttribute.cs
- SerializationObjectManager.cs
- InternalEnumValidator.cs
- CodeThrowExceptionStatement.cs
- RestHandler.cs
- Viewport3DAutomationPeer.cs
- Point3DAnimation.cs