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
- PageAdapter.cs
- DbConnectionInternal.cs
- SchemaMerger.cs
- GridPattern.cs
- SecureStringHasher.cs
- xamlnodes.cs
- ValidationHelper.cs
- MonthChangedEventArgs.cs
- safex509handles.cs
- RunInstallerAttribute.cs
- Transform3D.cs
- DataMisalignedException.cs
- URI.cs
- DataSpaceManager.cs
- TripleDESCryptoServiceProvider.cs
- Double.cs
- DeclarativeCatalogPart.cs
- DiscoveryRequestHandler.cs
- StylusShape.cs
- SettingsAttributeDictionary.cs
- ProcessHostFactoryHelper.cs
- parserscommon.cs
- DataColumnCollection.cs
- CompleteWizardStep.cs
- WindowsToolbar.cs
- AsyncResult.cs
- WindowsTreeView.cs
- SymLanguageVendor.cs
- OdbcDataReader.cs
- SizeAnimationBase.cs
- CodeTryCatchFinallyStatement.cs
- FileUpload.cs
- PeerNameRecordCollection.cs
- MatrixAnimationBase.cs
- FilterQuery.cs
- RuleCache.cs
- ECDiffieHellman.cs
- KnownTypesProvider.cs
- DispatchChannelSink.cs
- PropertyGridEditorPart.cs
- XmlNodeList.cs
- DataGrid.cs
- Brushes.cs
- BaseProcessor.cs
- XmlSchemaCollection.cs
- DrawingGroup.cs
- ItemContainerGenerator.cs
- X509Chain.cs
- SessionStateItemCollection.cs
- SamlAuthorizationDecisionStatement.cs
- EdmFunction.cs
- InputScopeConverter.cs
- MsmqIntegrationChannelFactory.cs
- ViewService.cs
- DataGridTableCollection.cs
- UnaryQueryOperator.cs
- WebAdminConfigurationHelper.cs
- UnsafeNativeMethods.cs
- WebPartRestoreVerb.cs
- ToolStripGripRenderEventArgs.cs
- XmlNullResolver.cs
- ObjectTypeMapping.cs
- ListBoxItemAutomationPeer.cs
- FrameworkContextData.cs
- CacheDependency.cs
- SettingsProviderCollection.cs
- _NetworkingPerfCounters.cs
- DefaultEventAttribute.cs
- PageThemeBuildProvider.cs
- XslTransform.cs
- RemotingAttributes.cs
- TextBoxBase.cs
- SignatureToken.cs
- DataGridCellItemAutomationPeer.cs
- TrustLevelCollection.cs
- Psha1DerivedKeyGeneratorHelper.cs
- ActionFrame.cs
- OdbcErrorCollection.cs
- WriteLineDesigner.xaml.cs
- MethodAccessException.cs
- InvalidDataException.cs
- JapaneseLunisolarCalendar.cs
- SignedXml.cs
- OutputCacheModule.cs
- InvocationExpression.cs
- StylusButtonCollection.cs
- CharUnicodeInfo.cs
- _SSPIWrapper.cs
- Thickness.cs
- FontFaceLayoutInfo.cs
- LayoutEvent.cs
- HttpChannelFactory.cs
- MemberMaps.cs
- SafeProcessHandle.cs
- ClockGroup.cs
- XmlParserContext.cs
- AutomationPeer.cs
- CacheVirtualItemsEvent.cs
- Journaling.cs
- XmlValueConverter.cs