| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using System.Threading;
- namespace Muchinfo.MTPClient.Infrastructure.LinkProxy
- {
- /// <summary>
- /// 异步结果
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class AsyncResult<T> : 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;
- }
- /// <summary>
- /// 设置完成
- /// </summary>
- /// <param name="result">The result.</param>
- /// <param name="responseTime">The response time.</param>
- 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();
- }
- /// <summary>
- /// 设置服务超时
- /// </summary>
- public void SetTimeOut()
- {
- this.IsCompleted = false;
- var manualReset = (this.AsyncWaitHandle as ManualResetEvent);
- if (manualReset == null)
- {
- return;
- }
- manualReset.Set();
- }
- /// <summary>
- /// 返回结果
- /// </summary>
- public T Result
- {
- get;
- private set;
- }
- /// <summary>
- /// 请求时间
- /// </summary>
- public DateTime RequestTime
- {
- get;
- private set;
- }
- /// <summary>
- /// 响应时间
- /// </summary>
- 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;
- }
- }
- }
|