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
- DataGridViewAccessibleObject.cs
- RemotingSurrogateSelector.cs
- UshortList2.cs
- ElementProxy.cs
- DetailsViewRowCollection.cs
- HttpResponse.cs
- Token.cs
- XamlStyleSerializer.cs
- LinearGradientBrush.cs
- ThreadStartException.cs
- TextEmbeddedObject.cs
- HwndProxyElementProvider.cs
- TextDecorationCollectionConverter.cs
- WindowsGraphicsCacheManager.cs
- DynamicValueConverter.cs
- DisplayInformation.cs
- TempFiles.cs
- XmlAtomicValue.cs
- Stack.cs
- StaticExtension.cs
- DictionaryEntry.cs
- DbProviderSpecificTypePropertyAttribute.cs
- AddingNewEventArgs.cs
- QueryCacheKey.cs
- ImageCodecInfoPrivate.cs
- dtdvalidator.cs
- Padding.cs
- SHA384.cs
- XmlTextReaderImpl.cs
- BitHelper.cs
- MethodBuilderInstantiation.cs
- HtmlWindow.cs
- MessageAction.cs
- GridViewRowEventArgs.cs
- EntitySqlQueryCacheEntry.cs
- PathTooLongException.cs
- CellNormalizer.cs
- CheckBoxFlatAdapter.cs
- PrinterUnitConvert.cs
- GlyphRunDrawing.cs
- WmlListAdapter.cs
- FusionWrap.cs
- RichTextBoxAutomationPeer.cs
- ResourceDictionaryCollection.cs
- HttpConfigurationContext.cs
- XmlMessageFormatter.cs
- ComponentCollection.cs
- UseLicense.cs
- RepeaterItem.cs
- COM2PropertyPageUITypeConverter.cs
- InheritanceContextHelper.cs
- FlowDocumentPageViewerAutomationPeer.cs
- KeyValueConfigurationElement.cs
- AnnotationMap.cs
- RequestQueryParser.cs
- DataGridViewHeaderCell.cs
- RowToFieldTransformer.cs
- SpeechSeg.cs
- AppSettingsSection.cs
- ChannelDispatcherCollection.cs
- CopyNamespacesAction.cs
- DecimalFormatter.cs
- ProtectedConfigurationSection.cs
- EntityObject.cs
- CounterSampleCalculator.cs
- FormatPage.cs
- ResourcePart.cs
- AuthorizationRule.cs
- GuidelineCollection.cs
- FixedTextBuilder.cs
- RegexParser.cs
- MatrixTransform.cs
- IIS7WorkerRequest.cs
- GridView.cs
- UpdateDelegates.Generated.cs
- MappingItemCollection.cs
- ToolStripItemDataObject.cs
- DataGridCell.cs
- EncryptedKey.cs
- PublishLicense.cs
- NgenServicingAttributes.cs
- TypeConverterHelper.cs
- ImageConverter.cs
- Point3D.cs
- NavigateEvent.cs
- TypeDelegator.cs
- SizeAnimation.cs
- CopyOfAction.cs
- ImageInfo.cs
- Pen.cs
- BinaryObjectReader.cs
- InfoCardSymmetricCrypto.cs
- SvcMapFileLoader.cs
- SerializerProvider.cs
- UnicodeEncoding.cs
- MenuCommands.cs
- IncrementalReadDecoders.cs
- MappedMetaModel.cs
- EntityContainerEmitter.cs
- PrePostDescendentsWalker.cs