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
- FileUtil.cs
- UInt16.cs
- PerformanceCounterLib.cs
- MinMaxParagraphWidth.cs
- LeaseManager.cs
- ToolCreatedEventArgs.cs
- DataGridViewCellCancelEventArgs.cs
- RelatedEnd.cs
- SqlRewriteScalarSubqueries.cs
- contentDescriptor.cs
- MetadataSet.cs
- EnumType.cs
- PlatformNotSupportedException.cs
- FileChangesMonitor.cs
- AutomationIdentifier.cs
- SHA512Managed.cs
- PageAsyncTaskManager.cs
- SystemPens.cs
- OutputCacheSection.cs
- HttpModuleAction.cs
- COM2PropertyDescriptor.cs
- NativeStructs.cs
- PenThreadWorker.cs
- TextSpanModifier.cs
- XPathExpr.cs
- WebPartUtil.cs
- HttpCacheVaryByContentEncodings.cs
- SerializationInfoEnumerator.cs
- SecurityDocument.cs
- AdPostCacheSubstitution.cs
- LogicalExpressionEditor.cs
- TypedDatasetGenerator.cs
- RequestDescription.cs
- ProfileSection.cs
- VerificationAttribute.cs
- CodeIdentifiers.cs
- ProcessHostFactoryHelper.cs
- XmlIterators.cs
- GenericXmlSecurityToken.cs
- Animatable.cs
- OleDbConnectionInternal.cs
- SmiRequestExecutor.cs
- ExtendedPropertiesHandler.cs
- _Connection.cs
- DataSourceControlBuilder.cs
- KeyTimeConverter.cs
- ZoneIdentityPermission.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- XPathAxisIterator.cs
- DeviceContexts.cs
- UInt64.cs
- ViewKeyConstraint.cs
- DynamicDiscoveryDocument.cs
- ProgressBarRenderer.cs
- ModelTreeEnumerator.cs
- TimelineCollection.cs
- ExpressionBindingsDialog.cs
- FormatterConverter.cs
- MinimizableAttributeTypeConverter.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- SimpleBitVector32.cs
- X509Certificate.cs
- UrlAuthFailedErrorFormatter.cs
- MSG.cs
- Compiler.cs
- QilTernary.cs
- SiteMapDataSourceView.cs
- PathGradientBrush.cs
- DataGridCellEditEndingEventArgs.cs
- DefaultValidator.cs
- SqlHelper.cs
- ValidationResult.cs
- Win32MouseDevice.cs
- SqlLiftIndependentRowExpressions.cs
- DocumentPage.cs
- NativeMethods.cs
- Assert.cs
- AggregateException.cs
- ZoomPercentageConverter.cs
- RoleManagerSection.cs
- ConfigurationLocation.cs
- TextPattern.cs
- HtmlTableCellCollection.cs
- SqlCommand.cs
- RequestCachingSection.cs
- DataGridColumn.cs
- _UriTypeConverter.cs
- ParameterBuilder.cs
- SqlRowUpdatedEvent.cs
- SqlUserDefinedTypeAttribute.cs
- XPathSelfQuery.cs
- Style.cs
- CodeCastExpression.cs
- ComponentCommands.cs
- DecoderNLS.cs
- QueryCoreOp.cs
- StateBag.cs
- StringAttributeCollection.cs
- SchemaElementDecl.cs
- WindowsRichEdit.cs