Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Utility / MonitorWrapper.cs / 1305600 / 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; } GC.SuppressFinalize(this); } 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; } GC.SuppressFinalize(this); } 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
- PrinterSettings.cs
- FrameworkContextData.cs
- Endpoint.cs
- ExpressionDumper.cs
- SignatureHelper.cs
- handlecollector.cs
- TextServicesCompartmentContext.cs
- StreamBodyWriter.cs
- uribuilder.cs
- SchemaNames.cs
- ComboBoxDesigner.cs
- Win32.cs
- List.cs
- AsyncCompletedEventArgs.cs
- FileDialogCustomPlacesCollection.cs
- ReceiveMessageContent.cs
- ZoneLinkButton.cs
- WebConfigurationFileMap.cs
- TransformProviderWrapper.cs
- DataGridColumnHeaderItemAutomationPeer.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- wgx_exports.cs
- DataGridViewUtilities.cs
- OdbcStatementHandle.cs
- SqlMethods.cs
- FixedFindEngine.cs
- MenuItemCollection.cs
- DragEventArgs.cs
- WsdlBuildProvider.cs
- WebConfigurationHost.cs
- JapaneseCalendar.cs
- SafeNativeMemoryHandle.cs
- TextSelection.cs
- WebPartZoneCollection.cs
- FunctionImportElement.cs
- InvokeBase.cs
- BamlRecords.cs
- StylusCollection.cs
- JoinTreeNode.cs
- mediapermission.cs
- mediaeventargs.cs
- IndexingContentUnit.cs
- XPathNodeIterator.cs
- ScriptMethodAttribute.cs
- TextServicesDisplayAttribute.cs
- Executor.cs
- DrawingCollection.cs
- NotFiniteNumberException.cs
- ReturnValue.cs
- Opcode.cs
- ToolboxComponentsCreatedEventArgs.cs
- ThreadStateException.cs
- SecurityElementBase.cs
- BrowserCapabilitiesCompiler.cs
- KeyTimeConverter.cs
- EastAsianLunisolarCalendar.cs
- VirtualizedCellInfoCollection.cs
- MaskInputRejectedEventArgs.cs
- Matrix.cs
- HttpClientCertificate.cs
- DirectoryInfo.cs
- XamlGridLengthSerializer.cs
- TypeBuilderInstantiation.cs
- ConfigUtil.cs
- TypeUnloadedException.cs
- Utilities.cs
- CustomBindingCollectionElement.cs
- EntityDataSourceDesignerHelper.cs
- XmlSerializationGeneratedCode.cs
- TextTreeInsertElementUndoUnit.cs
- Effect.cs
- InkCanvasAutomationPeer.cs
- ListViewGroupConverter.cs
- ReaderWriterLock.cs
- TaskHelper.cs
- RegexMatchCollection.cs
- DynamicILGenerator.cs
- CornerRadiusConverter.cs
- RectangleGeometry.cs
- DataControlPagerLinkButton.cs
- XmlAttributes.cs
- ProgressBar.cs
- RegexRunner.cs
- Form.cs
- TreeSet.cs
- SimpleHandlerFactory.cs
- ThaiBuddhistCalendar.cs
- BitmapEffectGroup.cs
- DataGridViewRowConverter.cs
- GuidConverter.cs
- Block.cs
- RegexGroupCollection.cs
- ZipIOExtraFieldZip64Element.cs
- RealProxy.cs
- WinEventHandler.cs
- Form.cs
- CompositeControlDesigner.cs
- WebPartActionVerb.cs
- WebBaseEventKeyComparer.cs
- ThaiBuddhistCalendar.cs