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
- CodeComment.cs
- EventData.cs
- RegionInfo.cs
- ParameterElement.cs
- JsonWriter.cs
- TextSchema.cs
- Relationship.cs
- ServiceObjectContainer.cs
- InterleavedZipPartStream.cs
- ByteConverter.cs
- CopyCodeAction.cs
- SqlFlattener.cs
- ParseHttpDate.cs
- StructuredTypeEmitter.cs
- GradientBrush.cs
- XmlAttributeOverrides.cs
- IItemProperties.cs
- PixelFormats.cs
- SessionStateContainer.cs
- XmlDataCollection.cs
- CapabilitiesUse.cs
- GridViewColumn.cs
- DefaultSerializationProviderAttribute.cs
- AssemblyFilter.cs
- WindowsGraphics.cs
- OracleParameterBinding.cs
- XmlCharCheckingReader.cs
- FixedSOMTableRow.cs
- SessionIDManager.cs
- HelpEvent.cs
- ProgressChangedEventArgs.cs
- RSAOAEPKeyExchangeFormatter.cs
- EntityContainerAssociationSet.cs
- DesignerActionTextItem.cs
- ExecutionEngineException.cs
- DataGridGeneralPage.cs
- odbcmetadatafactory.cs
- StackSpiller.Generated.cs
- HierarchicalDataBoundControlAdapter.cs
- SafeFileMapViewHandle.cs
- PathSegmentCollection.cs
- UInt16Storage.cs
- Path.cs
- KnownBoxes.cs
- EventLogQuery.cs
- AppAction.cs
- DbMetaDataFactory.cs
- updatecommandorderer.cs
- FontStyles.cs
- BackgroundFormatInfo.cs
- FloatMinMaxAggregationOperator.cs
- SByte.cs
- InternalTypeHelper.cs
- KeyInstance.cs
- TempFiles.cs
- DataRecordObjectView.cs
- ComPlusContractBehavior.cs
- HttpContextBase.cs
- ProfessionalColors.cs
- SqlExpressionNullability.cs
- FirstMatchCodeGroup.cs
- XmlEntityReference.cs
- GeometryModel3D.cs
- NotificationContext.cs
- RtfControls.cs
- XhtmlBasicObjectListAdapter.cs
- TypeGeneratedEventArgs.cs
- JulianCalendar.cs
- ObjectTypeMapping.cs
- TypeBuilder.cs
- RubberbandSelector.cs
- EmptyEnumerable.cs
- LinqDataSourceView.cs
- ZipQueryOperator.cs
- EdmType.cs
- AssociationEndMember.cs
- DataServiceHostWrapper.cs
- OleDbParameterCollection.cs
- WebConvert.cs
- PropertyToken.cs
- DefaultAuthorizationContext.cs
- KnownIds.cs
- AsyncCodeActivityContext.cs
- ItemMap.cs
- AuthenticatingEventArgs.cs
- ServiceHttpModule.cs
- EntityKey.cs
- SqlDataSourceCache.cs
- ContextToken.cs
- ClientOptions.cs
- SafeEventLogReadHandle.cs
- CallSiteOps.cs
- EventListenerClientSide.cs
- SortExpressionBuilder.cs
- FileUtil.cs
- ExpressionParser.cs
- ToolStripSystemRenderer.cs
- NetStream.cs
- ImpersonationContext.cs
- BufferBuilder.cs