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
- PageBuildProvider.cs
- StrokeCollection.cs
- XmlArrayItemAttribute.cs
- SharedStatics.cs
- validationstate.cs
- SafeEventLogWriteHandle.cs
- SymbolMethod.cs
- XmlSubtreeReader.cs
- Animatable.cs
- RowsCopiedEventArgs.cs
- CmsInterop.cs
- CodeTypeDelegate.cs
- LineSegment.cs
- ErasingStroke.cs
- OpenTypeLayoutCache.cs
- securitycriticaldata.cs
- ParserOptions.cs
- Activator.cs
- QuaternionAnimationUsingKeyFrames.cs
- FamilyMapCollection.cs
- RegexBoyerMoore.cs
- FamilyMapCollection.cs
- ReversePositionQuery.cs
- Dictionary.cs
- ICollection.cs
- MethodCallConverter.cs
- ListItemCollection.cs
- WorkflowQueueInfo.cs
- Event.cs
- MonikerProxyAttribute.cs
- ContractNamespaceAttribute.cs
- StatusStrip.cs
- Int32CAMarshaler.cs
- Vector3DCollection.cs
- PermissionRequestEvidence.cs
- Misc.cs
- HttpWebRequest.cs
- DetailsViewPagerRow.cs
- _AutoWebProxyScriptEngine.cs
- WebConfigurationFileMap.cs
- QueryOptionExpression.cs
- ScriptDescriptor.cs
- StylusButtonCollection.cs
- MouseActionConverter.cs
- PartitionedDataSource.cs
- Content.cs
- DataGridTable.cs
- InfoCardSymmetricAlgorithm.cs
- Boolean.cs
- MultiplexingDispatchMessageFormatter.cs
- StringConcat.cs
- DependencyPropertyDescriptor.cs
- ConfigXmlElement.cs
- PixelShader.cs
- ImageFormat.cs
- AnnotationDocumentPaginator.cs
- SafeNativeMethods.cs
- loginstatus.cs
- RightsManagementEncryptedStream.cs
- util.cs
- HwndAppCommandInputProvider.cs
- CloseCryptoHandleRequest.cs
- DesignerTransaction.cs
- SqlDataSourceView.cs
- NewArrayExpression.cs
- OverrideMode.cs
- AuthenticationSection.cs
- ParallelTimeline.cs
- httpserverutility.cs
- DataException.cs
- SQLBytes.cs
- FileStream.cs
- StorageSetMapping.cs
- ProgressChangedEventArgs.cs
- PolicyReader.cs
- SecurityTokenValidationException.cs
- InfoCardArgumentException.cs
- ApplicationProxyInternal.cs
- RetrieveVirtualItemEventArgs.cs
- AttributeXamlType.cs
- DataRecordInfo.cs
- DataSourceCache.cs
- BindingGroup.cs
- BitmapEffectvisualstate.cs
- OperationAbortedException.cs
- GridSplitter.cs
- XmlSchemaObject.cs
- ListChangedEventArgs.cs
- ToolStripContextMenu.cs
- BackgroundFormatInfo.cs
- _FtpControlStream.cs
- DataTrigger.cs
- CompareValidator.cs
- BoundColumn.cs
- SoapDocumentServiceAttribute.cs
- EntityViewGenerationAttribute.cs
- XmlNamespaceManager.cs
- ExpandCollapsePattern.cs
- WorkflowInstanceRecord.cs
- RetrieveVirtualItemEventArgs.cs