Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- CounterNameConverter.cs
- Deserializer.cs
- DelegateSerializationHolder.cs
- PaintEvent.cs
- PerformanceCounterManager.cs
- BasicBrowserDialog.designer.cs
- ParseHttpDate.cs
- OracleConnectionFactory.cs
- InstanceLockQueryResult.cs
- ImmutableObjectAttribute.cs
- AssemblyResourceLoader.cs
- MSHTMLHostUtil.cs
- EventItfInfo.cs
- ActiveXHost.cs
- RankException.cs
- CharEnumerator.cs
- Monitor.cs
- TableRow.cs
- LinkTarget.cs
- NavigateEvent.cs
- PseudoWebRequest.cs
- ChangePassword.cs
- FullTrustAssembly.cs
- XmlAnyElementAttribute.cs
- AuthenticationConfig.cs
- KeyEventArgs.cs
- UpdateCommand.cs
- RegisteredScript.cs
- ScrollEventArgs.cs
- UrlAuthFailedErrorFormatter.cs
- XmlSigningNodeWriter.cs
- AnnotationDocumentPaginator.cs
- UInt16.cs
- ImageFormat.cs
- TextBoxDesigner.cs
- OciEnlistContext.cs
- SelectionProviderWrapper.cs
- MobileComponentEditorPage.cs
- DirectoryInfo.cs
- SchemaContext.cs
- SettingsBindableAttribute.cs
- EdgeModeValidation.cs
- BufferCache.cs
- ToolBarOverflowPanel.cs
- MatcherBuilder.cs
- Literal.cs
- LoaderAllocator.cs
- templategroup.cs
- BrushConverter.cs
- GridViewHeaderRowPresenter.cs
- CopyNodeSetAction.cs
- Content.cs
- MemberExpressionHelper.cs
- ReceiveActivityValidator.cs
- TextEditorContextMenu.cs
- SharedDp.cs
- TraceSection.cs
- OdbcEnvironmentHandle.cs
- EmptyEnumerable.cs
- DecoderNLS.cs
- QilNode.cs
- NumberFormatter.cs
- _SslStream.cs
- ArraySubsetEnumerator.cs
- UnlockInstanceCommand.cs
- InputReportEventArgs.cs
- MarkupProperty.cs
- NamespaceQuery.cs
- FixedLineResult.cs
- DocumentXmlWriter.cs
- PeerNearMe.cs
- VectorAnimation.cs
- HttpDebugHandler.cs
- BaseResourcesBuildProvider.cs
- ParallelTimeline.cs
- DataGridViewSelectedColumnCollection.cs
- ClientSession.cs
- IndependentAnimationStorage.cs
- PointF.cs
- ListViewGroup.cs
- UnsafeNativeMethods.cs
- ToolBar.cs
- CacheEntry.cs
- TcpSocketManager.cs
- Point.cs
- InvokeMethod.cs
- DataReaderContainer.cs
- HandlerBase.cs
- NotImplementedException.cs
- UIElement3D.cs
- HashHelper.cs
- MetadataUtil.cs
- TextTreeUndoUnit.cs
- ObjectConverter.cs
- TemplateBindingExtensionConverter.cs
- WrappingXamlSchemaContext.cs
- KeyedHashAlgorithm.cs
- MemberPath.cs
- PackagePart.cs
- BinaryExpressionHelper.cs