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
- SqlErrorCollection.cs
- Expression.cs
- EtwTrace.cs
- RecordsAffectedEventArgs.cs
- AutomationProperties.cs
- DocumentApplicationJournalEntry.cs
- translator.cs
- BamlRecordWriter.cs
- XmlDigitalSignatureProcessor.cs
- ToolboxCategory.cs
- CheckoutException.cs
- AuthorizationSection.cs
- DefaultShape.cs
- GradientStopCollection.cs
- AttachedPropertyMethodSelector.cs
- SiteMapNodeItem.cs
- smtpconnection.cs
- ResourceDisplayNameAttribute.cs
- ResourceReferenceExpressionConverter.cs
- SoapCodeExporter.cs
- IPAddressCollection.cs
- AssemblyBuilderData.cs
- CharAnimationUsingKeyFrames.cs
- messageonlyhwndwrapper.cs
- ProgressBar.cs
- ImageFormatConverter.cs
- PropertyPathConverter.cs
- EntityViewContainer.cs
- DecoderReplacementFallback.cs
- HttpRuntime.cs
- SHA1CryptoServiceProvider.cs
- MimeMultiPart.cs
- WindowsSpinner.cs
- SqlDataSourceSummaryPanel.cs
- SecurityTokenSpecification.cs
- ImpersonateTokenRef.cs
- SqlClientWrapperSmiStreamChars.cs
- ExpressionBuilderContext.cs
- MouseEvent.cs
- CallSiteOps.cs
- PingOptions.cs
- StringInfo.cs
- backend.cs
- CssClassPropertyAttribute.cs
- MobileListItem.cs
- storepermissionattribute.cs
- TriggerCollection.cs
- LiteralSubsegment.cs
- OperatorExpressions.cs
- Material.cs
- SecurityChannelListener.cs
- DesignerProperties.cs
- SerializationSectionGroup.cs
- AtomMaterializerLog.cs
- FacetChecker.cs
- DataSourceView.cs
- StatusBarItem.cs
- XhtmlConformanceSection.cs
- Int32RectValueSerializer.cs
- PrinterSettings.cs
- DbCommandDefinition.cs
- COM2ExtendedTypeConverter.cs
- TextEditorParagraphs.cs
- ObjectQueryState.cs
- Table.cs
- OuterGlowBitmapEffect.cs
- UniqueConstraint.cs
- NonVisualControlAttribute.cs
- TagMapInfo.cs
- XmlCDATASection.cs
- DesignerActionUIStateChangeEventArgs.cs
- unsafenativemethodstextservices.cs
- AlternationConverter.cs
- DesignerWebPartChrome.cs
- SingletonChannelAcceptor.cs
- SendSecurityHeader.cs
- ToolStripDropDownItem.cs
- VisualStateManager.cs
- PrintDocument.cs
- PlainXmlWriter.cs
- ConsoleKeyInfo.cs
- LogAppendAsyncResult.cs
- XsdSchemaFileEditor.cs
- TimerExtension.cs
- SelectionRangeConverter.cs
- Funcletizer.cs
- XmlSchemaCompilationSettings.cs
- ExpressionVisitorHelpers.cs
- PointAnimation.cs
- EntityException.cs
- ChildDocumentBlock.cs
- XmlTextEncoder.cs
- FormsAuthenticationEventArgs.cs
- ToolboxBitmapAttribute.cs
- ControlPropertyNameConverter.cs
- WpfWebRequestHelper.cs
- Descriptor.cs
- UnsafeNativeMethodsTablet.cs
- ValueType.cs
- PageAsyncTaskManager.cs