/******************************************************************************
Module: AsyncResult.cs
Notices: Written by Jeffrey Richter
******************************************************************************/
using System;
using System.Diagnostics;
///////////////////////////////////////////////////////////////////////////////
namespace InTheHand.Net{
[DebuggerNonUserCode] // alanjmcf
internal class AsyncResult<TResult> : AsyncResultNoResult
{
// Field set when operation completes
private TResult m_result = default(TResult);
public AsyncResult(AsyncCallback asyncCallback, Object state) : base(asyncCallback, state) { }
[DebuggerNonUserCode] // alanjmcf
public void SetAsCompleted(TResult result, Boolean completedSynchronously)
{
// Save the asynchronous operation's result
m_result = result;
// Tell the base class that the operation completed sucessfully (no exception)
base.SetAsCompleted(null, completedSynchronously);
}
[DebuggerNonUserCode] // alanjmcf
public void SetAsCompleted(TResult result, AsyncResultCompletion completion)
{
// Save the asynchronous operation's result
m_result = result;
// Tell the base class that the operation completed sucessfully (no exception)
base.SetAsCompleted(null, completion);
}
[DebuggerNonUserCode] // alanjmcf
new public TResult EndInvoke()
{
base.EndInvoke(); // Wait until operation has completed
return m_result; // Return the result (if above didn't throw)
}
}
// alanjmcf
[DebuggerNonUserCode] // alanjmcf
internal class AsyncResult<TResult, TParams> : AsyncResult<TResult>
{
TParams m_args;
public AsyncResult(AsyncCallback asyncCallback, Object state, TParams args)
: base(asyncCallback, state)
{
m_args = args;
}
public TParams BeginParameters { get { return m_args; } }
}
}
//////////////////////////////// End of File //////////////////////////////////
|