예제 #1
0
        /// <summary>
        /// Advance execution of one member task (coroutine) by
        /// calling MoveNext() on it. Execution of tasks is interleaved
        /// in round-robin fashion.
        /// </summary>
        public bool MoveNext()
        {
            bool moveNext = false;

            while (!moveNext && NumCompleted < Tasks.Count)
            {
                if (!CompletedTasks.Contains(_taskIndex))
                {
                    moveNext = Tasks[_taskIndex].MoveNext();

                    if (!moveNext)
                    {
                        CompletedTasks.Add(_taskIndex);
                        OnCompleted?.Invoke(_taskIndex, Tasks[_taskIndex].Current);
                    }
                }

                _taskIndex++;
                if (_taskIndex >= Tasks.Count)
                {
                    _taskIndex = 0;
                }
            }

            return(moveNext);
        }
예제 #2
0
        /// <summary>
        /// Advance execution of the current subtask by a single step.
        /// </summary>
        public bool MoveNext()
        {
            if (State != ExecutionState.Running)
            {
                return(false);
            }

            bool   moveNext = false;
            object current  = null;

            try
            {
                while (!moveNext && _tasks.Count > 0)
                {
                    _stopwatch.Restart();
                    moveNext = _tasks[0].MoveNext();
                    _stopwatch.Stop();

                    _profilingData.Add(new ProfilingRecord {
                        TaskType     = _tasks[0].GetType(),
                        Milliseconds = _stopwatch.ElapsedMilliseconds
                    });

                    current = _tasks[0].Current;
                    if (!moveNext)
                    {
                        _tasks.RemoveAt(0);
                    }
                }
            }
            catch (Exception e)
            {
                State = ExecutionState.Exception;
                OnException?.Invoke(e);
                Clear();

                if (RethrowExceptionAfterCallbacks)
                {
                    throw;
                }

                return(false);
            }

            if (_tasks.Count == 0)
            {
                State = ExecutionState.Completed;
                OnCompleted?.Invoke((GameObject)current);
                Clear();
            }

            return(moveNext);
        }
예제 #3
0
        public void Create(string xpacksFolder, ImageMapInformation map, UpdateCallback updateCallback, CompletedCallback completedCallback)
        {
            IsFetchingData = true;
            Cancel         = false;

            try
            {
                // Create the Main texture.
                CreateTexture(xpacksFolder, map);
                if (!Cancel)
                {
                    completedCallback?.Invoke(true);
                }
            }
            catch
            {
                completedCallback?.Invoke(false); // Report in that something went wrong.
            }

            IsFetchingData = false;
        }
 private static async Task PerformTimeMeasuringAsync <T>(T profiler, TimeMeasureOptions options, Func <T, Task> handler) where T : TimeMeasureProfiler
 {
     try
     {
         profiler.Timer.Start();
         await handler(profiler).ContinueWithSuppressedContext();
     }
     catch (TargetInvocationException ex)
     {
         throw ex.InnerException ?? ex; // don't confuse the end-user with reflection related details; return the originating exception
     }
     finally
     {
         profiler.Timer.Stop();
         if (options.TimeMeasureCompletedThreshold == TimeSpan.Zero || profiler.Elapsed > options.TimeMeasureCompletedThreshold)
         {
             CompletedCallback?.Invoke(profiler);
         }
     }
 }
예제 #5
0
 public void ScavengeCompleted(ScavengeResult result, string error, TimeSpan elapsed)
 {
     Completed = true;
     Result    = result;
     CompletedCallback?.Invoke(this, EventArgs.Empty);
 }