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
- PropertyCondition.cs
- SoapSchemaExporter.cs
- ShaderEffect.cs
- StrokeCollectionDefaultValueFactory.cs
- EntityDataSourceWrapperCollection.cs
- Hashtable.cs
- XmlSchemaSimpleContent.cs
- GlyphRun.cs
- Input.cs
- XmlSchemaSimpleTypeList.cs
- AppDomainManager.cs
- WebPartAddingEventArgs.cs
- RawMouseInputReport.cs
- ToolStripTextBox.cs
- BodyGlyph.cs
- DynamicDataRouteHandler.cs
- RemoteDebugger.cs
- DataGridViewRowEventArgs.cs
- WindowsIPAddress.cs
- BrushConverter.cs
- SerialPort.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- CodeDomSerializer.cs
- Enlistment.cs
- MDIControlStrip.cs
- MergeFilterQuery.cs
- SystemTcpConnection.cs
- EventSinkHelperWriter.cs
- COAUTHIDENTITY.cs
- DateTimeFormatInfoScanner.cs
- OletxEnlistment.cs
- Debugger.cs
- NonParentingControl.cs
- EncoderExceptionFallback.cs
- WindowsComboBox.cs
- DataControlButton.cs
- AsymmetricSignatureFormatter.cs
- HuffModule.cs
- WorkflowApplicationUnloadedException.cs
- CopyOfAction.cs
- CollectionViewGroupRoot.cs
- TypeSemantics.cs
- Label.cs
- UnsafeNativeMethods.cs
- HttpCookiesSection.cs
- AnnotationComponentChooser.cs
- TempFiles.cs
- XmlSchemaAny.cs
- CacheOutputQuery.cs
- DynamicResourceExtension.cs
- PageAsyncTask.cs
- ConstructorBuilder.cs
- StylusPointPropertyId.cs
- DispatcherHookEventArgs.cs
- TypefaceCollection.cs
- DPCustomTypeDescriptor.cs
- TextElementEnumerator.cs
- TranslateTransform.cs
- VectorCollectionConverter.cs
- ColumnClickEvent.cs
- XmlAtomicValue.cs
- Int32Rect.cs
- Scheduler.cs
- SiteMapPath.cs
- TextEditorContextMenu.cs
- BitmapSource.cs
- cookiecontainer.cs
- OleDbParameter.cs
- CompositeScriptReferenceEventArgs.cs
- FormatSettings.cs
- Grammar.cs
- ResolveNameEventArgs.cs
- ReadingWritingEntityEventArgs.cs
- IdentityNotMappedException.cs
- PropertyConverter.cs
- IPGlobalProperties.cs
- InlineCollection.cs
- ReferenceEqualityComparer.cs
- listitem.cs
- ObfuscationAttribute.cs
- IdentityReference.cs
- XmlConvert.cs
- DoubleCollectionConverter.cs
- PostBackOptions.cs
- XPathNode.cs
- URL.cs
- assertwrapper.cs
- EdmSchemaError.cs
- filewebresponse.cs
- WebPartVerbsEventArgs.cs
- _IPv4Address.cs
- DataKeyCollection.cs
- Membership.cs
- BinaryFormatter.cs
- odbcmetadatacollectionnames.cs
- StateBag.cs
- Deflater.cs
- List.cs
- MimeTextImporter.cs
- Math.cs