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
- TypeNameConverter.cs
- TypeViewSchema.cs
- SurrogateSelector.cs
- DesignerHierarchicalDataSourceView.cs
- Identity.cs
- HMACSHA512.cs
- ECDiffieHellmanCngPublicKey.cs
- Part.cs
- GiveFeedbackEventArgs.cs
- ServiceSecurityContext.cs
- LayoutDump.cs
- DistributedTransactionPermission.cs
- DataObjectCopyingEventArgs.cs
- Errors.cs
- ImageConverter.cs
- Win32SafeHandles.cs
- ClientOptions.cs
- ContourSegment.cs
- Profiler.cs
- ConfigurationManagerHelperFactory.cs
- PictureBox.cs
- Win32.cs
- SamlAuthorizationDecisionClaimResource.cs
- HeaderedItemsControl.cs
- XmlJsonWriter.cs
- FrameworkElementFactoryMarkupObject.cs
- BinaryConverter.cs
- AnnotationComponentManager.cs
- QueryCursorEventArgs.cs
- DataServiceQueryContinuation.cs
- GeometryHitTestParameters.cs
- BoundColumn.cs
- MemberPath.cs
- SpeakCompletedEventArgs.cs
- cookie.cs
- FileAuthorizationModule.cs
- ServiceOperationInvoker.cs
- Scene3D.cs
- DictionaryTraceRecord.cs
- XsltFunctions.cs
- AuthenticationConfig.cs
- Helpers.cs
- BlobPersonalizationState.cs
- RectIndependentAnimationStorage.cs
- GiveFeedbackEventArgs.cs
- OperationCanceledException.cs
- BindUriHelper.cs
- TemplateColumn.cs
- WindowsAuthenticationEventArgs.cs
- Nullable.cs
- SignedInfo.cs
- _DisconnectOverlappedAsyncResult.cs
- SmiMetaData.cs
- NavigatorOutput.cs
- StaticSiteMapProvider.cs
- precedingquery.cs
- DesignerCommandSet.cs
- IDispatchConstantAttribute.cs
- MULTI_QI.cs
- StringDictionary.cs
- CreateParams.cs
- TextBoxLine.cs
- CompoundFileIOPermission.cs
- ScrollBarAutomationPeer.cs
- ComboBox.cs
- DataGridPageChangedEventArgs.cs
- SecurityChannel.cs
- OperationContractAttribute.cs
- TextBox.cs
- HttpContext.cs
- BaseAsyncResult.cs
- XmlSchemaExternal.cs
- LostFocusEventManager.cs
- FunctionImportMapping.cs
- ResolveMatchesApril2005.cs
- ParserHooks.cs
- XmlLoader.cs
- RectAnimationBase.cs
- ResourceReferenceExpression.cs
- WebBrowserDocumentCompletedEventHandler.cs
- PreviewKeyDownEventArgs.cs
- AddInContractAttribute.cs
- ConstraintConverter.cs
- FolderNameEditor.cs
- DebugTraceHelper.cs
- Pkcs7Signer.cs
- ListViewItem.cs
- Int32Storage.cs
- SqlProviderManifest.cs
- HtmlPanelAdapter.cs
- MultiAsyncResult.cs
- SkewTransform.cs
- KnownTypes.cs
- SqlCacheDependencySection.cs
- PipeException.cs
- KnownTypesHelper.cs
- CodeArgumentReferenceExpression.cs
- HtmlTableRow.cs
- EntityDataSourceReferenceGroup.cs
- XmlName.cs