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
- ReflectionServiceProvider.cs
- ClrPerspective.cs
- TextRangeEditTables.cs
- DocumentGridPage.cs
- Int32AnimationUsingKeyFrames.cs
- WebPartConnectionsCancelEventArgs.cs
- LocalTransaction.cs
- OpacityConverter.cs
- Directory.cs
- SafeFindHandle.cs
- Graphics.cs
- EnumMemberAttribute.cs
- GetWinFXPath.cs
- WebPartConnectionsConnectVerb.cs
- MembershipSection.cs
- TreeNodeStyleCollection.cs
- HtmlShimManager.cs
- WebPartsPersonalization.cs
- WmlLabelAdapter.cs
- Char.cs
- CustomTrackingRecord.cs
- RectAnimation.cs
- MimeMultiPart.cs
- ActiveXSite.cs
- NativeMethodsCLR.cs
- FullTextState.cs
- ExcCanonicalXml.cs
- TypedDataSetSchemaImporterExtension.cs
- RichTextBoxConstants.cs
- MeshGeometry3D.cs
- ActivityIdHeader.cs
- IndexedString.cs
- TranslateTransform3D.cs
- WorkflowNamespace.cs
- TransportContext.cs
- ContractInstanceProvider.cs
- SerializableAttribute.cs
- SecurityCriticalDataForSet.cs
- NeedSkipTokenVisitor.cs
- FrameworkContextData.cs
- FormDocumentDesigner.cs
- TextRangeBase.cs
- _UncName.cs
- _DisconnectOverlappedAsyncResult.cs
- SafeHandles.cs
- KeyToListMap.cs
- TypedTableBaseExtensions.cs
- WebPartChrome.cs
- Timer.cs
- ValidationSummary.cs
- Visual3D.cs
- Tracer.cs
- InboundActivityHelper.cs
- HtmlContainerControl.cs
- WindowsTokenRoleProvider.cs
- Wildcard.cs
- Hex.cs
- PermissionAttributes.cs
- BrowserCapabilitiesCodeGenerator.cs
- InfoCardRSACryptoProvider.cs
- ResourceReferenceExpressionConverter.cs
- CreateUserWizard.cs
- ImageList.cs
- ASCIIEncoding.cs
- UdpRetransmissionSettings.cs
- EventProvider.cs
- StylusPlugin.cs
- ColorDialog.cs
- SqlVersion.cs
- XPathArrayIterator.cs
- WindowsScrollBarBits.cs
- ExportOptions.cs
- BatchWriter.cs
- MatrixTransform3D.cs
- SerialStream.cs
- PartialCachingAttribute.cs
- FacetEnabledSchemaElement.cs
- X509Certificate.cs
- DataExpression.cs
- FontSource.cs
- SqlHelper.cs
- TreeViewBindingsEditor.cs
- TypeResolver.cs
- ComUdtElementCollection.cs
- WebPartMinimizeVerb.cs
- StatusBarPanelClickEvent.cs
- Button.cs
- ToolBarPanel.cs
- StringConverter.cs
- InstanceCreationEditor.cs
- HttpResponseHeader.cs
- NameValueSectionHandler.cs
- Monitor.cs
- CodeGen.cs
- StringBuilder.cs
- SplitContainer.cs
- SqlMethodAttribute.cs
- TableLayoutCellPaintEventArgs.cs
- Converter.cs
- RewritingValidator.cs