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
- ScriptReference.cs
- AppDomain.cs
- FixedSOMElement.cs
- NetworkInformationPermission.cs
- UrlPath.cs
- FreezableCollection.cs
- HostUtils.cs
- KeyFrames.cs
- LambdaCompiler.Generated.cs
- SchemaObjectWriter.cs
- JournalEntryStack.cs
- SessionStateUtil.cs
- Message.cs
- XmlUtil.cs
- DesignerAutoFormat.cs
- PeerApplicationLaunchInfo.cs
- DataGridViewRowConverter.cs
- UITypeEditors.cs
- AttributeUsageAttribute.cs
- CodeAttributeDeclarationCollection.cs
- Guid.cs
- DbRetry.cs
- DataGridViewCheckBoxCell.cs
- ClipboardProcessor.cs
- TextDecorationCollection.cs
- ServiceDescriptionReflector.cs
- EnumerableValidator.cs
- XmlStringTable.cs
- OracleDateTime.cs
- DocumentsTrace.cs
- SafeNativeMethodsCLR.cs
- figurelength.cs
- LeaseManager.cs
- AstTree.cs
- PingReply.cs
- MatrixTransform.cs
- WebAdminConfigurationHelper.cs
- NetSectionGroup.cs
- SiteMapHierarchicalDataSourceView.cs
- SiteMapSection.cs
- StringPropertyBuilder.cs
- SmtpException.cs
- SiteMapNodeCollection.cs
- Events.cs
- DispatcherHooks.cs
- DeviceContexts.cs
- ArraySortHelper.cs
- BaseDataList.cs
- MasterPageCodeDomTreeGenerator.cs
- GridEntry.cs
- DockProviderWrapper.cs
- HttpException.cs
- XmlDataFileEditor.cs
- FigureParaClient.cs
- UIElement.cs
- PageParser.cs
- FunctionDefinition.cs
- MultipleViewPattern.cs
- RSACryptoServiceProvider.cs
- XmlDataLoader.cs
- XmlSignificantWhitespace.cs
- XmlLoader.cs
- ILGenerator.cs
- XmlWrappingReader.cs
- SchemaConstraints.cs
- WindowsUpDown.cs
- StringCollectionMarkupSerializer.cs
- RowToParametersTransformer.cs
- GridViewColumnCollectionChangedEventArgs.cs
- DateTimeFormatInfoScanner.cs
- ObjectStateEntry.cs
- MenuAutomationPeer.cs
- SqlNotificationRequest.cs
- XmlAnyElementAttribute.cs
- Stackframe.cs
- ListViewItemMouseHoverEvent.cs
- ToolStripItemTextRenderEventArgs.cs
- CodeTypeReference.cs
- SmtpNegotiateAuthenticationModule.cs
- DispatchChannelSink.cs
- xmlfixedPageInfo.cs
- __ConsoleStream.cs
- DSACryptoServiceProvider.cs
- SQLByte.cs
- messageonlyhwndwrapper.cs
- XamlSerializerUtil.cs
- TimeSpan.cs
- IdSpace.cs
- DBDataPermission.cs
- TraceEventCache.cs
- sqlinternaltransaction.cs
- WorkflowQueueInfo.cs
- StateValidator.cs
- FixedSOMSemanticBox.cs
- LazyTextWriterCreator.cs
- FreeFormDragDropManager.cs
- OdbcRowUpdatingEvent.cs
- AlphaSortedEnumConverter.cs
- BufferedStream.cs
- _ListenerAsyncResult.cs