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
- CompiledRegexRunnerFactory.cs
- DataBindingsDialog.cs
- Binding.cs
- XslCompiledTransform.cs
- ExpressionNormalizer.cs
- ColorConvertedBitmap.cs
- TraceContextEventArgs.cs
- Component.cs
- FrameworkPropertyMetadata.cs
- BaseDataListDesigner.cs
- CategoryEditor.cs
- QueryOperatorEnumerator.cs
- QilReplaceVisitor.cs
- ReachBasicContext.cs
- RadialGradientBrush.cs
- ProviderUtil.cs
- SafePointer.cs
- DataObject.cs
- DocumentOrderQuery.cs
- ApplicationTrust.cs
- ReadOnlyCollectionBase.cs
- Timeline.cs
- PaginationProgressEventArgs.cs
- IRCollection.cs
- Object.cs
- ConfigXmlComment.cs
- SecondaryViewProvider.cs
- FocusManager.cs
- EventProviderClassic.cs
- WebBrowsableAttribute.cs
- HtmlProps.cs
- ComUdtElement.cs
- SqlStatistics.cs
- TableLayoutSettingsTypeConverter.cs
- ArraySortHelper.cs
- EncoderParameter.cs
- UIElement.cs
- Size.cs
- DataObject.cs
- ProjectionRewriter.cs
- EventMap.cs
- DataServiceExpressionVisitor.cs
- GridViewColumnHeader.cs
- SystemWebSectionGroup.cs
- DataListGeneralPage.cs
- EventLogQuery.cs
- CallbackTimeoutsBehavior.cs
- SqlUnionizer.cs
- DSASignatureFormatter.cs
- RenderData.cs
- HyperLink.cs
- TagPrefixAttribute.cs
- IOException.cs
- Attachment.cs
- Image.cs
- InsufficientMemoryException.cs
- XmlSchemaElement.cs
- ActiveXHost.cs
- PropertyChange.cs
- StrongNameUtility.cs
- WindowsIdentity.cs
- SafeSecurityHelper.cs
- DBSqlParserTable.cs
- StopStoryboard.cs
- RuleConditionDialog.Designer.cs
- DecoderFallbackWithFailureFlag.cs
- TabControlAutomationPeer.cs
- NestedContainer.cs
- Attributes.cs
- QilXmlWriter.cs
- DateTimeSerializationSection.cs
- PerformanceCountersElement.cs
- SplayTreeNode.cs
- OleDbConnectionFactory.cs
- Scene3D.cs
- CompositeDesignerAccessibleObject.cs
- TemplateControlParser.cs
- CacheAxisQuery.cs
- WinFormsSpinner.cs
- TreeNodeMouseHoverEvent.cs
- WindowsComboBox.cs
- SystemColorTracker.cs
- ConnectionManagementSection.cs
- CategoryAttribute.cs
- ParserStack.cs
- WebReferenceOptions.cs
- RuntimeVariableList.cs
- StringPropertyBuilder.cs
- DrawingContextDrawingContextWalker.cs
- CompositeScriptReferenceEventArgs.cs
- NameValuePair.cs
- ConstructorExpr.cs
- InkCanvasSelectionAdorner.cs
- FullTextState.cs
- CompiledIdentityConstraint.cs
- NetMsmqSecurity.cs
- CharAnimationBase.cs
- TraceContext.cs
- HostingEnvironment.cs
- SqlFileStream.cs