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
- PropertyToken.cs
- BufferedStream.cs
- COM2Enum.cs
- SplineKeyFrames.cs
- AttachInfo.cs
- DummyDataSource.cs
- CurrentChangingEventArgs.cs
- StoreUtilities.cs
- EventPrivateKey.cs
- FlatButtonAppearance.cs
- SessionEndedEventArgs.cs
- FlowLayout.cs
- LostFocusEventManager.cs
- SQLGuid.cs
- LowerCaseStringConverter.cs
- TypeResolver.cs
- ExceptionUtil.cs
- OutputCacheSettingsSection.cs
- CloudCollection.cs
- StatusBarDrawItemEvent.cs
- TrackingStringDictionary.cs
- ServiceDescriptionContext.cs
- CodeChecksumPragma.cs
- ListBindableAttribute.cs
- COM2IDispatchConverter.cs
- TraceSection.cs
- MessageQueuePermission.cs
- Vector3DCollection.cs
- QueueProcessor.cs
- IgnoreFileBuildProvider.cs
- MarginCollapsingState.cs
- DBAsyncResult.cs
- GraphicsPath.cs
- Int32.cs
- ResourceExpression.cs
- FastPropertyAccessor.cs
- DataGridViewColumnConverter.cs
- WebServiceReceive.cs
- TableLayoutSettings.cs
- MultipleCopiesCollection.cs
- Section.cs
- ConstraintStruct.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- WrappingXamlSchemaContext.cs
- XmlBaseReader.cs
- SHA1CryptoServiceProvider.cs
- MenuItemBinding.cs
- KeyInfo.cs
- SimpleModelProvider.cs
- Baml6Assembly.cs
- BufferedStream.cs
- ReflectionServiceProvider.cs
- _Semaphore.cs
- PasswordTextNavigator.cs
- BidPrivateBase.cs
- UnsafeNativeMethodsMilCoreApi.cs
- EventlogProvider.cs
- MatrixAnimationUsingPath.cs
- PageThemeBuildProvider.cs
- WebDescriptionAttribute.cs
- QuaternionRotation3D.cs
- TextContainerChangedEventArgs.cs
- DrawingState.cs
- XmlNamespaceManager.cs
- SqlCaseSimplifier.cs
- Privilege.cs
- HostingEnvironmentSection.cs
- MappingSource.cs
- Int16.cs
- PageCodeDomTreeGenerator.cs
- Propagator.Evaluator.cs
- Select.cs
- followingquery.cs
- ScrollPatternIdentifiers.cs
- OrderedDictionaryStateHelper.cs
- HierarchicalDataSourceControl.cs
- ClientSettings.cs
- mediaeventshelper.cs
- GridViewColumnHeader.cs
- SessionEndingCancelEventArgs.cs
- FileLevelControlBuilderAttribute.cs
- PropertyGridCommands.cs
- PrintingPermissionAttribute.cs
- ResourceContainer.cs
- GPPOINT.cs
- ImmutableAssemblyCacheEntry.cs
- JournalNavigationScope.cs
- NumberSubstitution.cs
- ApplicationSettingsBase.cs
- ObjectPersistData.cs
- DependencyObjectType.cs
- Compress.cs
- GridSplitter.cs
- ElementNotEnabledException.cs
- ExpandCollapseProviderWrapper.cs
- AsynchronousChannelMergeEnumerator.cs
- DataListItem.cs
- TableLayoutPanelDesigner.cs
- CryptoProvider.cs
- DrawingContext.cs