Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObservableTask{TResult}"/> class.
        /// </summary>
        /// <param name="taskToRun">The task that should be observed.</param>
        /// <param name="tracer">The tracer.</param>
        /// <param name="onTaskCompletedCallbabk">Method that should be executed after the task was completed.</param>
        public ObservableTask(Task <TResult> taskToRun, ITracer tracer, OnTaskCompletedEventHandler <TResult> onTaskCompletedCallbabk = null)
        {
            this.TaskToRun = taskToRun;
            this.tracer    = tracer;

            if (onTaskCompletedCallbabk != null)
            {
                this.OnTaskCompleted += onTaskCompletedCallbabk;
            }

            this.Result    = default(TResult);
            this.IsRunning = taskToRun.Status == TaskStatus.Running;

            if (!taskToRun.IsCompleted)
            {
#pragma warning disable 4014
                this.RunTaskAsync();
#pragma warning restore 4014
            }
            else
            {
                this.Result = this.GetTaskResult();
                this.OnTaskCompleted?.Invoke(this.Result);
            }
        }
Пример #2
0
 public ObservableTask(Task taskToRun, ITracer tracer, OnTaskCompletedEventHandler onTaskCompletedCallbabk = null)
     : base(TaskToRunWrapper(taskToRun), tracer, val => onTaskCompletedCallbabk?.Invoke())
 {
 }