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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SecUtil.cs
- CodeCatchClause.cs
- XsdCachingReader.cs
- SessionParameter.cs
- DictionaryBase.cs
- QualifiedCellIdBoolean.cs
- MaterialCollection.cs
- DelegateBodyWriter.cs
- ListBox.cs
- FontWeights.cs
- TemplateField.cs
- _SingleItemRequestCache.cs
- ListViewInsertEventArgs.cs
- ListControl.cs
- QueryOptionExpression.cs
- CompilerTypeWithParams.cs
- DeferredElementTreeState.cs
- ExtensibleClassFactory.cs
- Vector.cs
- ProcessInfo.cs
- DynamicQueryableWrapper.cs
- TextBoxBase.cs
- XPathChildIterator.cs
- SafeWaitHandle.cs
- TextElementCollection.cs
- ItemChangedEventArgs.cs
- Environment.cs
- ResXResourceReader.cs
- DataBoundControlAdapter.cs
- OrderPreservingSpoolingTask.cs
- Bitmap.cs
- DeviceContexts.cs
- Executor.cs
- DrawingAttributesDefaultValueFactory.cs
- BamlMapTable.cs
- TriggerActionCollection.cs
- MethodBuilder.cs
- XsdDateTime.cs
- SequenceQuery.cs
- MobileFormsAuthentication.cs
- storepermission.cs
- CompiledQueryCacheKey.cs
- NodeCounter.cs
- DataGridViewRowConverter.cs
- HttpPostLocalhostServerProtocol.cs
- MethodBuilderInstantiation.cs
- XsltArgumentList.cs
- StickyNoteContentControl.cs
- BasicCellRelation.cs
- Brush.cs
- LocalizationParserHooks.cs
- XPathNavigator.cs
- ProfileGroupSettingsCollection.cs
- FixedDocumentPaginator.cs
- Main.cs
- StyleSelector.cs
- PcmConverter.cs
- GotoExpression.cs
- DateTimeOffsetConverter.cs
- HttpApplication.cs
- StandardMenuStripVerb.cs
- Missing.cs
- DoubleCollection.cs
- AdRotatorDesigner.cs
- SQlBooleanStorage.cs
- RegularExpressionValidator.cs
- GeometryDrawing.cs
- Clock.cs
- ExternalDataExchangeService.cs
- CustomMenuItemCollection.cs
- Operator.cs
- HwndHostAutomationPeer.cs
- XmlNodeChangedEventArgs.cs
- ParagraphVisual.cs
- ListViewCancelEventArgs.cs
- NamedElement.cs
- ReadOnlyDataSource.cs
- ResourceProperty.cs
- VoiceSynthesis.cs
- ConditionalExpression.cs
- ApplicationFileParser.cs
- SafeHandles.cs
- SecurityTokenSpecification.cs
- ParameterBuilder.cs
- AnnotationResource.cs
- PersonalizationProviderCollection.cs
- ACE.cs
- ExternalException.cs
- OpenTypeCommon.cs
- XmlExtensionFunction.cs
- Line.cs
- DBSqlParserTable.cs
- FamilyMapCollection.cs
- Convert.cs
- XPathDescendantIterator.cs
- MissingMethodException.cs
- StylusEditingBehavior.cs
- RolePrincipal.cs
- GlyphTypeface.cs
- StatusBar.cs