Exemplo n.º 1
0
 public static Task ExecuteTask(IMultipleModel model, CancellationToken token)
 {
     return(Task.Run(async() => await model.ActionToExecute(token).ConfigureAwait(true), token)
            .ContinueWith((task) =>
     {
         model.ActionAfterComplete();
         model.IsFinish = true;
         return task;
     }, token, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.FromCurrentSynchronizationContext()));
 }
Exemplo n.º 2
0
        private ThreadModel CreateNewTask(IMultipleModel model)
        {
            CancellationTokenSource token = new CancellationTokenSource();

            return(new ThreadModel
            {
                Model = model,
                Task = MultiTaskFactory.ExecuteTask(model, token.Token),
                Token = token
            });
        }