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
- PenCursorManager.cs
- NullableConverter.cs
- ConfigurationElementProperty.cs
- XmlImplementation.cs
- XmlSchemaValidationException.cs
- AppliedDeviceFiltersEditor.cs
- DbConnectionFactory.cs
- WebRequestModuleElementCollection.cs
- HttpRequest.cs
- SchemaImporter.cs
- WSHttpBinding.cs
- NotFiniteNumberException.cs
- MembershipValidatePasswordEventArgs.cs
- ServiceHandle.cs
- Solver.cs
- ConsoleCancelEventArgs.cs
- EventArgs.cs
- TdsEnums.cs
- SystemNetworkInterface.cs
- ProfileGroupSettingsCollection.cs
- AppSecurityManager.cs
- ManagedCodeMarkers.cs
- SmtpException.cs
- MaskInputRejectedEventArgs.cs
- Selector.cs
- CachedPathData.cs
- JavaScriptObjectDeserializer.cs
- Source.cs
- ViewGenerator.cs
- DurationConverter.cs
- DocumentReferenceCollection.cs
- WebPartDisplayMode.cs
- SqlMetaData.cs
- NamespaceCollection.cs
- StrokeCollectionDefaultValueFactory.cs
- SponsorHelper.cs
- XmlElement.cs
- ConfigXmlCDataSection.cs
- SqlProviderServices.cs
- ActiveXMessageFormatter.cs
- ProviderConnectionPoint.cs
- ViewValidator.cs
- Dictionary.cs
- Calendar.cs
- WebPageTraceListener.cs
- ISFClipboardData.cs
- BamlLocalizationDictionary.cs
- SqlError.cs
- LogoValidationException.cs
- DataGridColumn.cs
- BaseTemplatedMobileComponentEditor.cs
- WmlCommandAdapter.cs
- DBCommand.cs
- NamedPipeDuplicateContext.cs
- WebBrowserHelper.cs
- RelatedPropertyManager.cs
- Calendar.cs
- XmlSerializerAssemblyAttribute.cs
- AndCondition.cs
- CheckBox.cs
- ApplicationSettingsBase.cs
- TypographyProperties.cs
- ContainsSearchOperator.cs
- Visitors.cs
- EncoderExceptionFallback.cs
- SafeIUnknown.cs
- XdrBuilder.cs
- SerialStream.cs
- XmlNodeChangedEventManager.cs
- ColorTransform.cs
- VBIdentifierNameEditor.cs
- FileDialogPermission.cs
- HttpProfileGroupBase.cs
- TextTreeObjectNode.cs
- DataTransferEventArgs.cs
- ObjectHandle.cs
- HelpKeywordAttribute.cs
- ContractsBCL.cs
- EntityModelBuildProvider.cs
- __ConsoleStream.cs
- SourceFileBuildProvider.cs
- ValidationRuleCollection.cs
- DataRowView.cs
- DataExpression.cs
- DefaultObjectMappingItemCollection.cs
- ArraySortHelper.cs
- Helper.cs
- CodeGotoStatement.cs
- AvTrace.cs
- StringFreezingAttribute.cs
- PublisherIdentityPermission.cs
- CacheDependency.cs
- GlyphRun.cs
- DesignerHost.cs
- HttpHeaderCollection.cs
- EventData.cs
- FrameworkPropertyMetadata.cs
- InplaceBitmapMetadataWriter.cs
- XmlSchema.cs
- Operand.cs