Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / ChainedAsyncResult.cs / 1 / ChainedAsyncResult.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.Collections.Generic;
using System.ServiceModel;
internal delegate IAsyncResult ChainedBeginHandler(TimeSpan timeout, AsyncCallback asyncCallback, object state);
internal delegate void ChainedEndHandler(IAsyncResult result);
class ChainedAsyncResult : AsyncResult
{
ChainedBeginHandler begin2;
ChainedEndHandler end1;
ChainedEndHandler end2;
TimeoutHelper timeoutHelper;
static AsyncCallback begin1Callback = DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Begin1Callback));
static AsyncCallback begin2Callback = DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Begin2Callback));
protected ChainedAsyncResult(TimeSpan timeout, AsyncCallback callback, object state)
: base(callback, state)
{
this.timeoutHelper = new TimeoutHelper(timeout);
}
public ChainedAsyncResult(TimeSpan timeout, AsyncCallback callback, object state, ChainedBeginHandler begin1, ChainedEndHandler end1, ChainedBeginHandler begin2, ChainedEndHandler end2)
: base(callback, state)
{
this.timeoutHelper = new TimeoutHelper(timeout);
Begin(begin1, end1, begin2, end2);
}
protected void Begin(ChainedBeginHandler begin1, ChainedEndHandler end1, ChainedBeginHandler begin2, ChainedEndHandler end2)
{
this.end1 = end1;
this.begin2 = begin2;
this.end2 = end2;
IAsyncResult result = begin1(this.timeoutHelper.RemainingTime(), begin1Callback, this);
if (!result.CompletedSynchronously)
return;
if (Begin1Completed(result))
{
this.Complete(true);
}
}
static void Begin1Callback(IAsyncResult result)
{
if (result.CompletedSynchronously)
return;
ChainedAsyncResult thisPtr = (ChainedAsyncResult)result.AsyncState;
bool completeSelf = false;
Exception completeException = null;
try
{
completeSelf = thisPtr.Begin1Completed(result);
}
#pragma warning suppress 56500 // covered by FxCOP
catch (Exception exception)
{
if (DiagnosticUtility.IsFatal(exception))
{
throw;
}
completeSelf = true;
completeException = exception;
}
if (completeSelf)
{
thisPtr.Complete(false, completeException);
}
}
bool Begin1Completed(IAsyncResult result)
{
end1(result);
result = begin2(this.timeoutHelper.RemainingTime(), begin2Callback, this);
if (!result.CompletedSynchronously)
return false;
end2(result);
return true;
}
static void Begin2Callback(IAsyncResult result)
{
if (result.CompletedSynchronously)
return;
ChainedAsyncResult thisPtr = (ChainedAsyncResult)result.AsyncState;
Exception completeException = null;
try
{
thisPtr.end2(result);
}
#pragma warning suppress 56500 // covered by FxCOP
catch (Exception exception)
{
if (DiagnosticUtility.IsFatal(exception))
{
throw;
}
completeException = exception;
}
thisPtr.Complete(false, completeException);
}
public static void End(IAsyncResult result)
{
AsyncResult.End(result);
}
}
internal class ChainedCloseAsyncResult : ChainedAsyncResult
{
IList collection;
public ChainedCloseAsyncResult(TimeSpan timeout, AsyncCallback callback, object state, ChainedBeginHandler begin1, ChainedEndHandler end1, IList collection)
: base(timeout, callback, state)
{
this.collection = collection;
Begin(BeginClose, EndClose, begin1, end1);
}
public ChainedCloseAsyncResult(TimeSpan timeout, AsyncCallback callback, object state, ChainedBeginHandler begin1, ChainedEndHandler end1, params ICommunicationObject[] objs)
: base(timeout, callback, state)
{
collection = new List();
if (objs!= null)
for (int index = 0; index < objs.Length; index++)
if (objs[index] != null)
collection.Add(objs[index]);
Begin(BeginClose, EndClose, begin1, end1);
}
IAsyncResult BeginClose(TimeSpan timeout, AsyncCallback callback, object state)
{
return new CloseCollectionAsyncResult(timeout, callback, state, collection);
}
void EndClose(IAsyncResult result)
{
CloseCollectionAsyncResult.End((CloseCollectionAsyncResult)result);
}
}
internal class ChainedOpenAsyncResult : ChainedAsyncResult
{
IList collection;
public ChainedOpenAsyncResult(TimeSpan timeout, AsyncCallback callback, object state, ChainedBeginHandler begin1, ChainedEndHandler end1, IList collection)
: base(timeout, callback, state)
{
this.collection = collection;
Begin(begin1, end1, BeginOpen, EndOpen);
}
public ChainedOpenAsyncResult(TimeSpan timeout, AsyncCallback callback, object state, ChainedBeginHandler begin1, ChainedEndHandler end1, params ICommunicationObject[] objs)
: base(timeout, callback, state)
{
collection = new List();
for (int index = 0; index < objs.Length; index++)
if (objs[index] != null)
collection.Add(objs[index]);
Begin(begin1, end1, BeginOpen, EndOpen);
}
IAsyncResult BeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
{
return new OpenCollectionAsyncResult(timeout, callback, state, collection);
}
void EndOpen(IAsyncResult result)
{
OpenCollectionAsyncResult.End((OpenCollectionAsyncResult)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
- GridEntryCollection.cs
- LocalBuilder.cs
- WebService.cs
- NullToBooleanConverter.cs
- ClientConfigPaths.cs
- EntityTransaction.cs
- InvokeWebServiceDesigner.cs
- SoapClientProtocol.cs
- InstanceCreationEditor.cs
- MinimizableAttributeTypeConverter.cs
- ObjectIDGenerator.cs
- AuthenticationServiceManager.cs
- ClientSession.cs
- HtmlDocument.cs
- SourceFileBuildProvider.cs
- ConstructorNeedsTagAttribute.cs
- XmlSchemaAnyAttribute.cs
- Transactions.cs
- ValidationHelpers.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- FileDialog_Vista_Interop.cs
- ErrorWebPart.cs
- TreeViewImageKeyConverter.cs
- HttpListenerTimeoutManager.cs
- LocalizedNameDescriptionPair.cs
- bindurihelper.cs
- HtmlInputImage.cs
- EditorZone.cs
- ProtocolsConfigurationHandler.cs
- MediaPlayer.cs
- JapaneseLunisolarCalendar.cs
- FileDetails.cs
- Pair.cs
- TreeNodeStyleCollection.cs
- Invariant.cs
- FormsAuthenticationUserCollection.cs
- DispatcherExceptionEventArgs.cs
- IgnoreFlushAndCloseStream.cs
- ScrollChrome.cs
- SetterBaseCollection.cs
- LineSegment.cs
- DictationGrammar.cs
- ProcessStartInfo.cs
- CultureInfoConverter.cs
- BitHelper.cs
- HtmlTextArea.cs
- COMException.cs
- __FastResourceComparer.cs
- DotAtomReader.cs
- XmlEncodedRawTextWriter.cs
- RegexCode.cs
- EtwProvider.cs
- WebServiceTypeData.cs
- DateTimeOffset.cs
- ReturnEventArgs.cs
- SoapSchemaMember.cs
- SqlFileStream.cs
- X509LogoTypeExtension.cs
- Console.cs
- CipherData.cs
- IDispatchConstantAttribute.cs
- WaitForChangedResult.cs
- SchemaLookupTable.cs
- SqlDataAdapter.cs
- SimpleTextLine.cs
- ItemContainerPattern.cs
- Compress.cs
- DataGridViewCellValueEventArgs.cs
- UniqueID.cs
- WebPartVerbsEventArgs.cs
- TableColumnCollectionInternal.cs
- Funcletizer.cs
- OracleSqlParser.cs
- ParserHooks.cs
- NoneExcludedImageIndexConverter.cs
- TreeViewImageKeyConverter.cs
- Parallel.cs
- EntityStoreSchemaGenerator.cs
- CertificateManager.cs
- ContextMenuStripActionList.cs
- ClientFormsAuthenticationCredentials.cs
- RelationshipType.cs
- ClientApiGenerator.cs
- TransformGroup.cs
- SelectionProcessor.cs
- MimePart.cs
- RemotingException.cs
- XpsFontSubsetter.cs
- OracleException.cs
- LocalizationComments.cs
- PartialCachingControl.cs
- SqlCrossApplyToCrossJoin.cs
- XhtmlBasicObjectListAdapter.cs
- OperatorExpressions.cs
- TemplateBindingExtensionConverter.cs
- HealthMonitoringSection.cs
- ColumnWidthChangedEvent.cs
- IisTraceListener.cs
- SqlMethodAttribute.cs
- ExtentJoinTreeNode.cs