Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Utility / MonitorWrapper.cs / 1305600 / 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; } GC.SuppressFinalize(this); } 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; } GC.SuppressFinalize(this); } 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
- DecimalConverter.cs
- SvcMapFileLoader.cs
- SetStoryboardSpeedRatio.cs
- WebPartAddingEventArgs.cs
- BulletChrome.cs
- StrokeNodeData.cs
- _FtpDataStream.cs
- DocumentSequenceHighlightLayer.cs
- WebPartUtil.cs
- TextViewBase.cs
- TextEncodedRawTextWriter.cs
- SecurityContext.cs
- DataGridRow.cs
- InputLanguage.cs
- FullTrustAssemblyCollection.cs
- AdditionalEntityFunctions.cs
- ResourceSet.cs
- ClientSettings.cs
- PowerStatus.cs
- HostSecurityManager.cs
- WebScriptMetadataFormatter.cs
- ScrollData.cs
- LoginUtil.cs
- MultipartContentParser.cs
- XmlSerializationReader.cs
- SystemResourceHost.cs
- SHA384Managed.cs
- AnonymousIdentificationModule.cs
- ProfilePropertyMetadata.cs
- EntityKey.cs
- TextEditor.cs
- EventPrivateKey.cs
- SqlAliasesReferenced.cs
- ListSourceHelper.cs
- SqlClientFactory.cs
- PropertyInformationCollection.cs
- WebRequestModuleElement.cs
- BuildProvidersCompiler.cs
- CodeTypeDelegate.cs
- LightweightEntityWrapper.cs
- BasicExpressionVisitor.cs
- CodeMethodInvokeExpression.cs
- SpanIndex.cs
- BitmapEffect.cs
- GcSettings.cs
- querybuilder.cs
- SimpleMailWebEventProvider.cs
- SequenceNumber.cs
- PropertyChangingEventArgs.cs
- SqlParameterCollection.cs
- PerspectiveCamera.cs
- TextEditorThreadLocalStore.cs
- Identifier.cs
- SortQuery.cs
- OleDbTransaction.cs
- PartialClassGenerationTaskInternal.cs
- ExceptionRoutedEventArgs.cs
- KnownTypeHelper.cs
- MexBindingElement.cs
- TraceInternal.cs
- DataColumnChangeEvent.cs
- XmlSchemaFacet.cs
- RepeaterItem.cs
- Font.cs
- ServerIdentity.cs
- IPAddressCollection.cs
- UidManager.cs
- BitmapCache.cs
- ParenExpr.cs
- SqlLiftIndependentRowExpressions.cs
- XmlUnspecifiedAttribute.cs
- TextBox.cs
- XmlQueryOutput.cs
- Win32.cs
- SecurityTokenTypes.cs
- DeflateStream.cs
- Padding.cs
- Registry.cs
- SmtpNegotiateAuthenticationModule.cs
- WebPartVerbsEventArgs.cs
- TableItemProviderWrapper.cs
- IndicShape.cs
- EdmScalarPropertyAttribute.cs
- WorkflowTimerService.cs
- CompilationSection.cs
- ProtocolElement.cs
- ToggleProviderWrapper.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- HorizontalAlignConverter.cs
- TextServicesProperty.cs
- ComponentChangingEvent.cs
- ProofTokenCryptoHandle.cs
- InternalBufferOverflowException.cs
- RectangleHotSpot.cs
- TreeView.cs
- TemplateBindingExpression.cs
- UserMapPath.cs
- XPathSingletonIterator.cs
- DataSetViewSchema.cs
- ButtonBaseAdapter.cs