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
- DataTablePropertyDescriptor.cs
- Brush.cs
- SqlHelper.cs
- VBCodeProvider.cs
- ObjectListFieldsPage.cs
- KeySpline.cs
- Range.cs
- AbstractExpressions.cs
- BaseValidator.cs
- ProgressPage.cs
- SqlWorkflowPersistenceService.cs
- PolyQuadraticBezierSegment.cs
- BindingWorker.cs
- SqlBulkCopyColumnMapping.cs
- CacheManager.cs
- DoubleSumAggregationOperator.cs
- BlurEffect.cs
- DataGridCellClipboardEventArgs.cs
- WebConfigurationHost.cs
- Literal.cs
- HttpDictionary.cs
- HostingEnvironmentWrapper.cs
- SoapCodeExporter.cs
- DeliveryStrategy.cs
- SmtpNetworkElement.cs
- WsdlWriter.cs
- ResourceManager.cs
- Char.cs
- ConvertEvent.cs
- MethodBody.cs
- DesignerLoader.cs
- RegexCompiler.cs
- GenericParameterDataContract.cs
- GeometryHitTestResult.cs
- SafeProcessHandle.cs
- ConfigurationValues.cs
- QueryOperationResponseOfT.cs
- RtfControls.cs
- GZipDecoder.cs
- ToolStripItemEventArgs.cs
- ObsoleteAttribute.cs
- ExpressionTable.cs
- CfgParser.cs
- PolicyStatement.cs
- ContainerControlDesigner.cs
- ArrangedElementCollection.cs
- DataControlFieldCell.cs
- ProfilePropertySettings.cs
- XmlSchemaAny.cs
- FileDialog.cs
- InvalidContentTypeException.cs
- StatusBar.cs
- PopupControlService.cs
- MediaScriptCommandRoutedEventArgs.cs
- Dictionary.cs
- TemplateKeyConverter.cs
- KnownTypesHelper.cs
- Parameter.cs
- StreamGeometry.cs
- UntrustedRecipientException.cs
- WindowsBrush.cs
- Timeline.cs
- BlockUIContainer.cs
- FormsAuthenticationConfiguration.cs
- CompilerResults.cs
- MethodImplAttribute.cs
- ObjectTag.cs
- SystemResourceKey.cs
- WebServiceParameterData.cs
- TargetControlTypeAttribute.cs
- FrameSecurityDescriptor.cs
- WebPartEventArgs.cs
- GPPOINT.cs
- DiscoveryViaBehavior.cs
- CheckBox.cs
- RemoveFromCollection.cs
- XmlSerializerFactory.cs
- ClassGenerator.cs
- Message.cs
- PackageRelationship.cs
- EntityTemplateUserControl.cs
- ListSortDescription.cs
- ScriptReferenceEventArgs.cs
- ValidationHelpers.cs
- SchemaManager.cs
- DataColumnMappingCollection.cs
- BamlCollectionHolder.cs
- GridViewRowPresenter.cs
- ObjectIDGenerator.cs
- TimeSpanValidatorAttribute.cs
- GlobalItem.cs
- Nodes.cs
- MeasureData.cs
- TextRangeProviderWrapper.cs
- BuildResult.cs
- RegistryConfigurationProvider.cs
- SqlBuilder.cs
- TimeoutValidationAttribute.cs
- Point3DAnimationBase.cs
- BitmapDownload.cs