Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / CloseCollectionAsyncResult.cs / 1 / CloseCollectionAsyncResult.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel { using System.Collections.Generic; using System.Threading; class CloseCollectionAsyncResult : AsyncResult { bool completedSynchronously; Exception exception; static AsyncCallback nestedCallback = DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Callback)); int count; public CloseCollectionAsyncResult(TimeSpan timeout, AsyncCallback otherCallback, object state, IListcollection) : base(otherCallback, state) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); completedSynchronously = true; count = collection.Count; if (count == 0) { Complete(true); return; } for (int index = 0; index < collection.Count; index++) { CallbackState callbackState = new CallbackState(this, collection[index]); IAsyncResult result; try { result = collection[index].BeginClose(timeoutHelper.RemainingTime(), nestedCallback, callbackState); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) { throw; } Decrement(true, e); collection[index].Abort(); continue; } if (result.CompletedSynchronously) { CompleteClose(collection[index], result); } } } void CompleteClose(ICommunicationObject communicationObject, IAsyncResult result) { Exception closeException = null; try { communicationObject.EndClose(result); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) { throw; } closeException = e; communicationObject.Abort(); } Decrement(result.CompletedSynchronously, closeException); } static void Callback(IAsyncResult result) { if (result.CompletedSynchronously) { return; } CallbackState callbackState = (CallbackState)result.AsyncState; callbackState.Result.CompleteClose(callbackState.Instance, result); } void Decrement(bool completedSynchronously) { if (completedSynchronously == false) this.completedSynchronously = false; if (Interlocked.Decrement(ref count) == 0) { if (this.exception != null) Complete(this.completedSynchronously, this.exception); else Complete(this.completedSynchronously); } } void Decrement(bool completedSynchronously, Exception exception) { this.exception = exception; this.Decrement(completedSynchronously); } public static void End(IAsyncResult result) { AsyncResult.End (result); } class CallbackState { ICommunicationObject instance; CloseCollectionAsyncResult result; public CallbackState(CloseCollectionAsyncResult result, ICommunicationObject instance) { this.result = result; this.instance = instance; } public ICommunicationObject Instance { get { return instance; } } public CloseCollectionAsyncResult Result { get { return result; } } } } } // 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
- GeometryGroup.cs
- FileAuthorizationModule.cs
- MulticastNotSupportedException.cs
- ExpressionContext.cs
- XmlSchemaAttributeGroupRef.cs
- TextLineResult.cs
- IntSumAggregationOperator.cs
- DependencyPropertyDescriptor.cs
- ProfileModule.cs
- BindingExpressionUncommonField.cs
- BufferedGraphicsManager.cs
- CacheDependency.cs
- CompositeDataBoundControl.cs
- ReadOnlyDataSourceView.cs
- PointLightBase.cs
- AccessedThroughPropertyAttribute.cs
- DataListCommandEventArgs.cs
- BitStream.cs
- HtmlWindowCollection.cs
- StylusButtonCollection.cs
- RegistryExceptionHelper.cs
- TemplatedMailWebEventProvider.cs
- XmlSchemaComplexContent.cs
- FontDriver.cs
- MouseBinding.cs
- Expression.cs
- shaper.cs
- ServiceOperationParameter.cs
- Version.cs
- PropertyValueUIItem.cs
- DataGridViewLayoutData.cs
- TablePattern.cs
- Vector3DCollection.cs
- PrivilegeNotHeldException.cs
- NamespaceEmitter.cs
- PanelDesigner.cs
- CryptographicAttribute.cs
- GenerateHelper.cs
- StatusBar.cs
- RemotingSurrogateSelector.cs
- OdbcError.cs
- HttpCookieCollection.cs
- XmlStreamedByteStreamReader.cs
- ColorAnimationUsingKeyFrames.cs
- GeneralTransform3DGroup.cs
- StrokeIntersection.cs
- HttpCapabilitiesSectionHandler.cs
- NameValueFileSectionHandler.cs
- WebPartCollection.cs
- QueryTaskGroupState.cs
- UpdateProgress.cs
- ActivityXamlServices.cs
- DataSetUtil.cs
- DocumentApplicationJournalEntry.cs
- CursorConverter.cs
- ValueHandle.cs
- CallbackTimeoutsElement.cs
- ExitEventArgs.cs
- EndOfStreamException.cs
- FileStream.cs
- ToolStripItemRenderEventArgs.cs
- TargetConverter.cs
- LocationUpdates.cs
- Parameter.cs
- InteropBitmapSource.cs
- TargetParameterCountException.cs
- SqlClientPermission.cs
- CodeAttributeArgument.cs
- WebPartConnectionsCloseVerb.cs
- WebServiceAttribute.cs
- RegexWriter.cs
- HttpResponseMessageProperty.cs
- GeneralTransform3DTo2DTo3D.cs
- WebBrowser.cs
- StringStorage.cs
- URLString.cs
- ByteRangeDownloader.cs
- BitmapSourceSafeMILHandle.cs
- NamespaceInfo.cs
- HtmlToClrEventProxy.cs
- SendMailErrorEventArgs.cs
- CompilerInfo.cs
- SizeF.cs
- ValidationResult.cs
- Deflater.cs
- RelationshipType.cs
- StreamAsIStream.cs
- ActiveXContainer.cs
- InstanceLockLostException.cs
- RoutedCommand.cs
- RootDesignerSerializerAttribute.cs
- TreeNodeStyle.cs
- Rijndael.cs
- ToolStripDropDownButton.cs
- RowToParametersTransformer.cs
- SecureEnvironment.cs
- SpeechUI.cs
- ReferenceEqualityComparer.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- SystemMulticastIPAddressInformation.cs