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
- WebEventCodes.cs
- SettingsPropertyIsReadOnlyException.cs
- ToolStripTemplateNode.cs
- FixedSOMFixedBlock.cs
- GridViewAutoFormat.cs
- PriorityBindingExpression.cs
- Point3D.cs
- BordersPage.cs
- ConfigXmlCDataSection.cs
- ChildTable.cs
- PeerDuplexChannelListener.cs
- ActivityDesignerResources.cs
- DeviceContext.cs
- OptimisticConcurrencyException.cs
- WebServiceReceive.cs
- WsatServiceCertificate.cs
- StreamSecurityUpgradeInitiator.cs
- IdentityManager.cs
- ConfigurationPropertyCollection.cs
- XmlValidatingReader.cs
- Hex.cs
- ProcessHost.cs
- RootProfilePropertySettingsCollection.cs
- CompatibleComparer.cs
- TreeChangeInfo.cs
- SafeIUnknown.cs
- TypeUsageBuilder.cs
- KnownBoxes.cs
- RefreshPropertiesAttribute.cs
- COM2ExtendedTypeConverter.cs
- _NTAuthentication.cs
- SchemaCollectionCompiler.cs
- ConnectionsZoneDesigner.cs
- IsolatedStorageFilePermission.cs
- IntersectQueryOperator.cs
- SignedInfo.cs
- Stylesheet.cs
- Calendar.cs
- Selection.cs
- FormViewInsertEventArgs.cs
- StringPropertyBuilder.cs
- ObjectQueryProvider.cs
- HtmlShimManager.cs
- PointLightBase.cs
- DateTimeFormatInfoScanner.cs
- SmiGettersStream.cs
- FilterElement.cs
- RectangleHotSpot.cs
- WizardStepBase.cs
- httpstaticobjectscollection.cs
- WebConvert.cs
- TypeInitializationException.cs
- CacheChildrenQuery.cs
- LogStore.cs
- NumericPagerField.cs
- WebPartDisplayModeCancelEventArgs.cs
- XmlSchemaComplexType.cs
- DragStartedEventArgs.cs
- DetailsView.cs
- ValidationRuleCollection.cs
- TabItemWrapperAutomationPeer.cs
- XmlILStorageConverter.cs
- SqlDataReaderSmi.cs
- DeviceSpecificChoiceCollection.cs
- TranslateTransform.cs
- DesignerView.xaml.cs
- StringFunctions.cs
- PriorityChain.cs
- MaskedTextBox.cs
- MatrixStack.cs
- ReflectionPermission.cs
- Light.cs
- DataGrid.cs
- Decimal.cs
- TextElementAutomationPeer.cs
- Size3DConverter.cs
- WmlCalendarAdapter.cs
- Trace.cs
- CellPartitioner.cs
- DBNull.cs
- StylusLogic.cs
- ContentDisposition.cs
- Int16AnimationUsingKeyFrames.cs
- TextServicesProperty.cs
- BindStream.cs
- WebBrowserSiteBase.cs
- ConsoleCancelEventArgs.cs
- SqlNotificationRequest.cs
- CodeGenerationManager.cs
- Adorner.cs
- SchemaNames.cs
- PropertyPathConverter.cs
- AspCompat.cs
- AdvancedBindingEditor.cs
- SystemParameters.cs
- RequestStatusBarUpdateEventArgs.cs
- SerializationAttributes.cs
- DocComment.cs
- CompleteWizardStep.cs
- PeerTransportElement.cs