Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / OpenCollectionAsyncResult.cs / 1 / OpenCollectionAsyncResult.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel { using System.Collections.Generic; using System.Threading; internal class OpenCollectionAsyncResult : AsyncResult { bool completedSynchronously; Exception exception; static AsyncCallback nestedCallback = DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Callback)); int count; TimeoutHelper timeoutHelper; public OpenCollectionAsyncResult(TimeSpan timeout, AsyncCallback otherCallback, object state, IListcollection) : base(otherCallback, state) { this.timeoutHelper = new TimeoutHelper(timeout); completedSynchronously = true; count = collection.Count; if (count == 0) { Complete(true); return; } for (int index = 0; index < collection.Count; index++) { // Throw exception if there was a failure calling EndOpen in the callback (skips remaining items) if (this.exception != null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.exception); CallbackState callbackState = new CallbackState(this, collection[index]); IAsyncResult result = collection[index].BeginOpen(this.timeoutHelper.RemainingTime(), nestedCallback, callbackState); if (result.CompletedSynchronously) { collection[index].EndOpen(result); Decrement(true); } } } static void Callback(IAsyncResult result) { if (result.CompletedSynchronously) return; CallbackState callbackState = (CallbackState)result.AsyncState; try { callbackState.Instance.EndOpen(result); callbackState.Result.Decrement(false); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) throw; callbackState.Result.Decrement(false, e); } } 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; OpenCollectionAsyncResult result; public CallbackState(OpenCollectionAsyncResult result, ICommunicationObject instance) { this.result = result; this.instance = instance; } public ICommunicationObject Instance { get { return instance; } } public OpenCollectionAsyncResult 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
- HMACSHA384.cs
- RealProxy.cs
- HtmlToClrEventProxy.cs
- FilteredSchemaElementLookUpTable.cs
- MetafileEditor.cs
- UnsafeMethods.cs
- MarshalDirectiveException.cs
- ChildChangedEventArgs.cs
- WeakReferenceEnumerator.cs
- SectionUpdates.cs
- LocalizeDesigner.cs
- CellConstant.cs
- XmlTextEncoder.cs
- SQLInt32Storage.cs
- ObjectDisposedException.cs
- Ticks.cs
- JsonFormatGeneratorStatics.cs
- Helpers.cs
- DynamicPropertyHolder.cs
- ComPlusServiceLoader.cs
- AuthenticationService.cs
- FreeFormDesigner.cs
- Privilege.cs
- GridLengthConverter.cs
- StoreItemCollection.cs
- EdmConstants.cs
- WebBrowserUriTypeConverter.cs
- ProcessThread.cs
- CqlWriter.cs
- XmlDocumentFragment.cs
- FilterRepeater.cs
- ActivityWithResult.cs
- PropertyEmitterBase.cs
- SimpleType.cs
- Vector3DValueSerializer.cs
- XmlSerializerFaultFormatter.cs
- DesignerExtenders.cs
- SelectionWordBreaker.cs
- FrameworkTextComposition.cs
- Sequence.cs
- IdentityHolder.cs
- StrokeCollection2.cs
- BlurEffect.cs
- XPathAncestorIterator.cs
- HotSpot.cs
- safex509handles.cs
- AdobeCFFWrapper.cs
- XamlSerializerUtil.cs
- D3DImage.cs
- MultiPropertyDescriptorGridEntry.cs
- XPathItem.cs
- ActionNotSupportedException.cs
- WbemProvider.cs
- BinaryObjectReader.cs
- InitiatorSessionSymmetricTransportSecurityProtocol.cs
- ObjectConverter.cs
- ParseNumbers.cs
- AutomationEvent.cs
- ParameterCollection.cs
- QilChoice.cs
- DefaultAsyncDataDispatcher.cs
- CellLabel.cs
- LineUtil.cs
- DocumentAutomationPeer.cs
- BooleanExpr.cs
- ConfigurationPropertyCollection.cs
- TabletDevice.cs
- DbConnectionPoolCounters.cs
- PointCollectionValueSerializer.cs
- DtrList.cs
- StateMachineDesignerPaint.cs
- EventTrigger.cs
- SchemaMapping.cs
- FormViewInsertedEventArgs.cs
- OdbcConnectionString.cs
- RadioButtonAutomationPeer.cs
- ParameterToken.cs
- Triplet.cs
- ModelVisual3D.cs
- StatusBarAutomationPeer.cs
- QueryCacheManager.cs
- TreeWalkHelper.cs
- VisualStyleRenderer.cs
- X509ChainElement.cs
- ObjectDataSourceFilteringEventArgs.cs
- ToolStripSplitButton.cs
- ValidationHelper.cs
- SafeEventLogWriteHandle.cs
- ImageAttributes.cs
- DBPropSet.cs
- Constraint.cs
- XmlSerializerFactory.cs
- Style.cs
- PngBitmapEncoder.cs
- XmlCodeExporter.cs
- SettingsPropertyValue.cs
- UriTemplateVariablePathSegment.cs
- KeyTime.cs
- GAC.cs
- ProtectedConfigurationSection.cs