Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- LicFileLicenseProvider.cs
- Size3D.cs
- controlskin.cs
- CssClassPropertyAttribute.cs
- ProviderConnectionPoint.cs
- TextCharacters.cs
- ListArgumentProvider.cs
- UserUseLicenseDictionaryLoader.cs
- DataGridViewBindingCompleteEventArgs.cs
- MenuItemAutomationPeer.cs
- FrugalMap.cs
- _NetRes.cs
- SizeAnimationClockResource.cs
- ControlBuilderAttribute.cs
- FullTextState.cs
- IDispatchConstantAttribute.cs
- Style.cs
- InheritanceAttribute.cs
- DataControlButton.cs
- MessageBodyDescription.cs
- ApplicationServicesHostFactory.cs
- XmlReflectionMember.cs
- EnumerableRowCollectionExtensions.cs
- DocumentPageView.cs
- Soap12ProtocolReflector.cs
- SplashScreen.cs
- ImageSourceConverter.cs
- ReadContentAsBinaryHelper.cs
- TreeNodeSelectionProcessor.cs
- EnvironmentPermission.cs
- SurrogateSelector.cs
- MsmqHostedTransportConfiguration.cs
- DropShadowBitmapEffect.cs
- ZoneLinkButton.cs
- InvalidCastException.cs
- WebPartExportVerb.cs
- WebHttpBindingCollectionElement.cs
- HttpModuleActionCollection.cs
- AnnotationService.cs
- SqlInfoMessageEvent.cs
- LogStore.cs
- JpegBitmapDecoder.cs
- BrushConverter.cs
- CompressionTracing.cs
- InfiniteIntConverter.cs
- ZeroOpNode.cs
- XmlReader.cs
- __FastResourceComparer.cs
- LogicalTreeHelper.cs
- DoubleLinkListEnumerator.cs
- MouseActionConverter.cs
- ReadOnlyTernaryTree.cs
- MultiTrigger.cs
- ListSortDescriptionCollection.cs
- HttpFileCollectionWrapper.cs
- GPRECT.cs
- RuntimeEnvironment.cs
- XmlDataSourceView.cs
- UnsafeNativeMethods.cs
- FormsAuthenticationTicket.cs
- SvcMapFileSerializer.cs
- RepeaterItemEventArgs.cs
- MarkupCompilePass1.cs
- NameValueConfigurationCollection.cs
- NavigationPropertyEmitter.cs
- HttpBufferlessInputStream.cs
- GridViewCommandEventArgs.cs
- MaxMessageSizeStream.cs
- Stack.cs
- FormClosedEvent.cs
- ScriptReferenceBase.cs
- ConfigXmlWhitespace.cs
- ServiceRoute.cs
- SafeViewOfFileHandle.cs
- CommonDialog.cs
- XmlSchemaAppInfo.cs
- SafeNativeMethodsCLR.cs
- DataGridViewButtonColumn.cs
- Exception.cs
- NativeCompoundFileAPIs.cs
- OleDbRowUpdatingEvent.cs
- KeyEvent.cs
- ObjectCloneHelper.cs
- MonthCalendar.cs
- AutomationAttributeInfo.cs
- SurrogateDataContract.cs
- SoapAttributes.cs
- CodeConstructor.cs
- TransportBindingElementImporter.cs
- CapacityStreamGeometryContext.cs
- SafeHandle.cs
- TemplateNameScope.cs
- StdValidatorsAndConverters.cs
- HtmlEncodedRawTextWriter.cs
- String.cs
- CodeTypeConstructor.cs
- CodeTypeReference.cs
- BaseCAMarshaler.cs
- AffineTransform3D.cs
- DataKeyArray.cs