Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / SynchronizedDisposablePool.cs / 1 / SynchronizedDisposablePool.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel { using System.Collections.Generic; using System.Threading; class SynchronizedDisposablePoolwhere T : class, IDisposable { List items; int maxCount; bool disposed; public SynchronizedDisposablePool(int maxCount) { this.items = new List (); this.maxCount = maxCount; } object ThisLock { get { return this; } } public void Dispose() { T[] items; lock (ThisLock) { if (!disposed) { disposed = true; if (this.items.Count > 0) { items = new T[this.items.Count]; this.items.CopyTo(items, 0); this.items.Clear(); } else { items = null; } } else { items = null; } } if (items != null) { for (int i = 0; i < items.Length; i++) { items[i].Dispose(); } } } public bool Return(T value) { if (!disposed && this.items.Count < this.maxCount) { lock (ThisLock) { if (!disposed && this.items.Count < this.maxCount) { this.items.Add(value); return true; } } } return false; } public T Take() { if (!disposed && this.items.Count > 0) { lock (ThisLock) { if (!disposed && this.items.Count > 0) { int index = this.items.Count - 1; T item = this.items[index]; this.items.RemoveAt(index); return item; } } } return null; } } } // 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
- X509CertificateRecipientServiceCredential.cs
- PageHandlerFactory.cs
- Storyboard.cs
- Stream.cs
- LoginAutoFormat.cs
- SizeConverter.cs
- DispatchChannelSink.cs
- TreeBuilderXamlTranslator.cs
- HtmlInputFile.cs
- smtppermission.cs
- Process.cs
- NeutralResourcesLanguageAttribute.cs
- Misc.cs
- DataPagerFieldCollection.cs
- AttributeTableBuilder.cs
- DataViewManagerListItemTypeDescriptor.cs
- PseudoWebRequest.cs
- ClonableStack.cs
- UseLicense.cs
- Mapping.cs
- MeshGeometry3D.cs
- DataViewListener.cs
- DataBoundLiteralControl.cs
- CultureInfoConverter.cs
- ListBoxItem.cs
- DataError.cs
- GPStream.cs
- OutputScopeManager.cs
- DataStorage.cs
- Pipe.cs
- UpdateProgress.cs
- RemoteCryptoTokenProvider.cs
- TextHidden.cs
- TransformerInfo.cs
- ReachDocumentSequenceSerializer.cs
- SymbolEqualComparer.cs
- DataGridCellClipboardEventArgs.cs
- EditorPartCollection.cs
- Codec.cs
- PersonalizationStateQuery.cs
- SessionParameter.cs
- HyperLinkField.cs
- AppDomainGrammarProxy.cs
- Regex.cs
- AssemblyBuilder.cs
- WeakReferenceKey.cs
- DrawingGroup.cs
- RightsManagementLicense.cs
- SQlBooleanStorage.cs
- DesignerTransaction.cs
- GetWinFXPath.cs
- AffineTransform3D.cs
- CroppedBitmap.cs
- GridView.cs
- WindowInteractionStateTracker.cs
- SqlDataSourceSelectingEventArgs.cs
- ContractReference.cs
- StateElementCollection.cs
- Membership.cs
- ControllableStoryboardAction.cs
- ObjectViewQueryResultData.cs
- JournalEntryListConverter.cs
- MouseDevice.cs
- unsafenativemethodsother.cs
- ToolboxItem.cs
- XMLDiffLoader.cs
- RewritingProcessor.cs
- Oci.cs
- SqlResolver.cs
- SplayTreeNode.cs
- SwitchCase.cs
- QualifiedCellIdBoolean.cs
- RoleManagerEventArgs.cs
- IndexedEnumerable.cs
- ConstructorBuilder.cs
- TransformCryptoHandle.cs
- MouseGesture.cs
- DataGridColumnHeaderAutomationPeer.cs
- LinqDataSource.cs
- BaseResourcesBuildProvider.cs
- WinOEToolBoxItem.cs
- SHA1Cng.cs
- ApplicationActivator.cs
- XmlMembersMapping.cs
- SelectionEditingBehavior.cs
- ObjectAnimationUsingKeyFrames.cs
- DefaultHttpHandler.cs
- AppDomain.cs
- PathHelper.cs
- CreateRefExpr.cs
- ByteStream.cs
- SecureStringHasher.cs
- PolyQuadraticBezierSegment.cs
- FlowPanelDesigner.cs
- StringUtil.cs
- FrameworkTemplate.cs
- SafeLibraryHandle.cs
- ThicknessAnimation.cs
- Merger.cs
- EmbeddedObject.cs