using System;
using System.Threading;
namespace Muchinfo.MTPClient.Infrastructure.LinkProxy
{
///
/// 异步结果
///
///
public class AsyncResult : IAsyncResult // where T : Tas.BusinessManager.DataContract.ResponseBase
{
public AsyncResult()
{
this.AsyncWaitHandle = new ManualResetEvent(false);
this.RequestTime = DateTime.Now;
}
public AsyncResult(DateTime reqeustTime)
{
this.AsyncWaitHandle = new ManualResetEvent(false);
this.RequestTime = reqeustTime;
}
///
/// 设置完成
///
/// The result.
/// The response time.
public void Complete(T result, DateTime responseTime)
{
this.ResponseTime = responseTime;
this.Result = result;
this.IsCompleted = true;
var manualReset = (this.AsyncWaitHandle as ManualResetEvent);
if (manualReset == null)
{
return;
}
manualReset.Set();
}
///
/// 设置服务超时
///
public void SetTimeOut()
{
this.IsCompleted = false;
var manualReset = (this.AsyncWaitHandle as ManualResetEvent);
if (manualReset == null)
{
return;
}
manualReset.Set();
}
///
/// 返回结果
///
public T Result
{
get;
private set;
}
///
/// 请求时间
///
public DateTime RequestTime
{
get;
private set;
}
///
/// 响应时间
///
public DateTime ResponseTime
{
get;
private set;
}
public WaitHandle AsyncWaitHandle
{
get;
private set;
}
public bool CompletedSynchronously
{
get
{
return false;
}
}
public object AsyncState
{
get;
private set;
}
public bool IsCompleted
{
get;
private set;
}
}
}