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
- TempFiles.cs
- __Error.cs
- HistoryEventArgs.cs
- EntityTypeBase.cs
- UnmanagedHandle.cs
- SafeNativeMethods.cs
- PolygonHotSpot.cs
- GridViewRowCollection.cs
- FontFamily.cs
- ChtmlLinkAdapter.cs
- ContentPlaceHolderDesigner.cs
- CalendarData.cs
- SchemaName.cs
- ToolStripPanelSelectionGlyph.cs
- Animatable.cs
- ZipQueryOperator.cs
- PropertyDescriptor.cs
- XPathDocumentBuilder.cs
- CharEnumerator.cs
- InkCanvasFeedbackAdorner.cs
- RichTextBoxAutomationPeer.cs
- ConfigurationManagerInternal.cs
- DoubleAnimation.cs
- BypassElement.cs
- ToolZone.cs
- ListViewItem.cs
- ExpandedWrapper.cs
- EmptyReadOnlyDictionaryInternal.cs
- UIPermission.cs
- DirectionalLight.cs
- PerfCounters.cs
- ExtensionSimplifierMarkupObject.cs
- SynchronizedDisposablePool.cs
- MsdtcClusterUtils.cs
- CodeDOMProvider.cs
- BamlStream.cs
- Model3D.cs
- DoubleCollection.cs
- DataGridViewAddColumnDialog.cs
- HealthMonitoringSection.cs
- ToolStripContentPanel.cs
- AppSettingsReader.cs
- RuleInfoComparer.cs
- HttpCookieCollection.cs
- DiagnosticTrace.cs
- DataRowChangeEvent.cs
- SqlRetyper.cs
- ObjectViewListener.cs
- MarkupCompilePass2.cs
- CodeAccessSecurityEngine.cs
- DelegateBodyWriter.cs
- SHA1Managed.cs
- FormViewUpdatedEventArgs.cs
- WebPartsPersonalizationAuthorization.cs
- DecimalStorage.cs
- RadioButton.cs
- DbConnectionStringCommon.cs
- ToolConsole.cs
- Transform.cs
- DPCustomTypeDescriptor.cs
- ImageDesigner.cs
- DESCryptoServiceProvider.cs
- DbParameterCollection.cs
- MimePart.cs
- RowToFieldTransformer.cs
- DocumentSequence.cs
- LocationReferenceValue.cs
- FrameAutomationPeer.cs
- OleDbErrorCollection.cs
- ProcessModelInfo.cs
- SettingsPropertyIsReadOnlyException.cs
- FileLevelControlBuilderAttribute.cs
- SafeProcessHandle.cs
- IdentityManager.cs
- QuaternionAnimationBase.cs
- ValidationError.cs
- X509Certificate2.cs
- MultiPageTextView.cs
- TypeLoadException.cs
- DesignerActionItemCollection.cs
- PerformanceCounterNameAttribute.cs
- SamlConditions.cs
- DesignerView.xaml.cs
- FlowDocumentReader.cs
- PersonalizationStateInfoCollection.cs
- TrackingParameters.cs
- TextFormatterContext.cs
- DataGridHeaderBorder.cs
- ListViewSelectEventArgs.cs
- PlanCompiler.cs
- TdsParserHelperClasses.cs
- SqlConnectionHelper.cs
- ProxySimple.cs
- SubclassTypeValidator.cs
- InstanceOwner.cs
- Pkcs9Attribute.cs
- EmptyEnumerator.cs
- ColorPalette.cs
- HttpResponseHeader.cs
- path.cs