Beispiel #1
0
 // TODO: Put strings into the resources.
 //
 public static TValue Execute <TValue>(this IAsyncOperator <TValue> op, int millisecondsTimeout)
 {
     op.EnsureNotNull(nameof(op));
     //
     if (op.IsCompleted)
     {
         return(op.Result);
     }
     else if (millisecondsTimeout == 0)
     {
         throw new TimeoutException(message: $"The operation was not completed within the specified timeout. Timeout expired.{Environment.NewLine}\tOperation:{op.FmtStr().GNLI2()}{Environment.NewLine}\tTimeout:{Environment.NewLine}{TimeSpan.FromMilliseconds(millisecondsTimeout).FmtStr().Constant().IndentLines2()}");
     }
     else
     {
         var task = op.ExecuteAsync().Unwrap();
         if (task.Wait(millisecondsTimeout: millisecondsTimeout))
         {
             return(task.Result);
         }
         else
         {
             throw new TimeoutException(message: $"The operation was not completed within the specified timeout. Timeout expired.{Environment.NewLine}\tOperation:{op.FmtStr().GNLI2()}{Environment.NewLine}\tTimeout:{Environment.NewLine}{TimeSpan.FromMilliseconds(millisecondsTimeout).FmtStr().Constant().IndentLines2()}");
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public AsyncOperate(IAsyncOperator @operator, int timerout = 100)
        {
            this.timerout = timerout;

            //@operator.SetAO(this);
            LogUpdate = () =>
            {
                isDone   = @operator.GetIsDoneState();
                progress = @operator.GetProcess();
                progress = HMath.Clamp01(progress);
                Log      = @operator.GetLog();
                HLog     = @operator.GetHLog();
                _logs.Add(HLog);
            };
        }
Beispiel #3
0
 public static TValue Execute <TValue>(this IAsyncOperator <TValue> op)
 => Execute(op: op, millisecondsTimeout: TaskUtilities.DefaultAsyncTimeoutMilliseconds);
Beispiel #4
0
 internal AsyncOperation(AsyncOperation?preceeding, IAsyncOperator op)
 {
     Operator             = op;
     State                = AsyncOperationState.Initial;
     _preceedingOperation = preceeding;
 }
Beispiel #5
0
 internal AsyncOperation(IAsyncOperator op)
     : this(null, op)
 {
 }
 internal AsyncOperation(AsyncOperation preceeding, IAsyncOperator op)
     : base(preceeding, op)
 {
 }