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
- ObjectTypeMapping.cs
- WebBrowserUriTypeConverter.cs
- AttachInfo.cs
- DtcInterfaces.cs
- CollectionContainer.cs
- CryptoApi.cs
- TemplatedWizardStep.cs
- AppDomainInfo.cs
- DataGridAutoFormatDialog.cs
- RestHandler.cs
- SchemaImporterExtensionsSection.cs
- PixelShader.cs
- WebSysDisplayNameAttribute.cs
- XmlSchemaImport.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- SpellCheck.cs
- BufferedGraphicsManager.cs
- UnsafeNetInfoNativeMethods.cs
- DodSequenceMerge.cs
- _FixedSizeReader.cs
- Pair.cs
- StreamWriter.cs
- DataGridViewAutoSizeModeEventArgs.cs
- ValidatedControlConverter.cs
- DataGridItemEventArgs.cs
- MachineKeySection.cs
- Subtree.cs
- EmptyEnumerator.cs
- PackageProperties.cs
- NegationPusher.cs
- QueryOptionExpression.cs
- StreamResourceInfo.cs
- RijndaelCryptoServiceProvider.cs
- SymbolType.cs
- MetabaseSettingsIis7.cs
- SizeChangedInfo.cs
- BoundsDrawingContextWalker.cs
- Point.cs
- EventPropertyMap.cs
- MemberHolder.cs
- GrammarBuilder.cs
- ReceiveActivityDesigner.cs
- FixedSOMSemanticBox.cs
- StringCollection.cs
- RegexGroup.cs
- RegexCompiler.cs
- ThemeInfoAttribute.cs
- HttpRuntimeSection.cs
- ReceiveContextCollection.cs
- TableRowsCollectionEditor.cs
- ElementNotEnabledException.cs
- ResourceProviderFactory.cs
- BrowserCapabilitiesFactory.cs
- FileLogRecordStream.cs
- Listen.cs
- ColorMap.cs
- MetadataCache.cs
- DataObjectFieldAttribute.cs
- WebConfigurationHostFileChange.cs
- ThicknessConverter.cs
- XmlExtensionFunction.cs
- MenuItem.cs
- BindingExpression.cs
- Wizard.cs
- EastAsianLunisolarCalendar.cs
- Assembly.cs
- DomNameTable.cs
- MetadataUtilsSmi.cs
- NamespaceExpr.cs
- PropertyMapper.cs
- wgx_exports.cs
- Memoizer.cs
- GridViewColumn.cs
- LogAppendAsyncResult.cs
- ContentTextAutomationPeer.cs
- TagPrefixCollection.cs
- UmAlQuraCalendar.cs
- RecipientServiceModelSecurityTokenRequirement.cs
- MultiView.cs
- TextSpan.cs
- SqlHelper.cs
- HandleCollector.cs
- FontCacheUtil.cs
- QfeChecker.cs
- QueryPageSettingsEventArgs.cs
- CompatibleIComparer.cs
- RegistrySecurity.cs
- PersonalizationState.cs
- ScriptModule.cs
- StylusPointProperty.cs
- EmbossBitmapEffect.cs
- MemberRelationshipService.cs
- XmlNamespaceMappingCollection.cs
- NoResizeHandleGlyph.cs
- COM2ExtendedBrowsingHandler.cs
- X509KeyIdentifierClauseType.cs
- Int32AnimationBase.cs
- Resources.Designer.cs
- GridProviderWrapper.cs
- TextFormatter.cs