Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- UserControlCodeDomTreeGenerator.cs
- ValidationUtility.cs
- Msmq4PoisonHandler.cs
- KeyValueSerializer.cs
- MetadataArtifactLoaderResource.cs
- ValidationErrorCollection.cs
- XslAst.cs
- ActivityIdHeader.cs
- CatalogZoneAutoFormat.cs
- TextTabProperties.cs
- ServiceRoute.cs
- InfocardInteractiveChannelInitializer.cs
- LoaderAllocator.cs
- TemplateColumn.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- ZipIOExtraFieldElement.cs
- ToolStripItemImageRenderEventArgs.cs
- SettingsBase.cs
- Span.cs
- FileChangeNotifier.cs
- FlowNode.cs
- RawStylusSystemGestureInputReport.cs
- ResourceSetExpression.cs
- RuleConditionDialog.Designer.cs
- FormsAuthenticationCredentials.cs
- MetadataSet.cs
- SmtpAuthenticationManager.cs
- HwndHost.cs
- BevelBitmapEffect.cs
- SwitchLevelAttribute.cs
- XmlSchemas.cs
- HierarchicalDataBoundControl.cs
- SuppressMergeCheckAttribute.cs
- WebServiceParameterData.cs
- PrimitiveType.cs
- ChannelTraceRecord.cs
- HotSpotCollectionEditor.cs
- BindableAttribute.cs
- DataGridViewRowHeaderCell.cs
- SecurityDocument.cs
- PhonemeEventArgs.cs
- TextClipboardData.cs
- RNGCryptoServiceProvider.cs
- ChineseLunisolarCalendar.cs
- LinkArea.cs
- UInt16Converter.cs
- SecondaryIndexList.cs
- DoubleLinkListEnumerator.cs
- DataGridLinkButton.cs
- TimeoutConverter.cs
- Schema.cs
- UnionCodeGroup.cs
- _LoggingObject.cs
- DoubleAnimationUsingPath.cs
- ArrayConverter.cs
- AmbientProperties.cs
- StructuredCompositeActivityDesigner.cs
- LiteralDesigner.cs
- WindowsImpersonationContext.cs
- ProtocolsConfigurationHandler.cs
- ContainsRowNumberChecker.cs
- BinaryConverter.cs
- CornerRadius.cs
- DeclarativeCatalogPart.cs
- GuidConverter.cs
- PolyQuadraticBezierSegment.cs
- BindingNavigator.cs
- Scripts.cs
- GroupStyle.cs
- ResourceDescriptionAttribute.cs
- PropertyPathConverter.cs
- QueryContinueDragEventArgs.cs
- SrgsRulesCollection.cs
- SelectorAutomationPeer.cs
- DESCryptoServiceProvider.cs
- PropertyCondition.cs
- ThicknessAnimationBase.cs
- PackageProperties.cs
- BlockCollection.cs
- PersonalizationStateQuery.cs
- PeerCustomResolverBindingElement.cs
- SchemaNotation.cs
- Maps.cs
- XmlDesigner.cs
- XmlnsDictionary.cs
- Floater.cs
- Composition.cs
- PasswordRecovery.cs
- FormViewRow.cs
- LayoutTable.cs
- _RequestCacheProtocol.cs
- ViewLoader.cs
- Canvas.cs
- DocumentAutomationPeer.cs
- Comparer.cs
- ParseChildrenAsPropertiesAttribute.cs
- CdpEqualityComparer.cs
- HostedTransportConfigurationBase.cs
- HtmlInputPassword.cs
- LicenseProviderAttribute.cs