Beispiel #1
0
        public static void Invoke(int taskID, IEnumerable <ActionModel> actions, bool isTest = false, bool isChildren = false)
        {
            if (actions == null)
            {
                return;
            }
            CancellationTokenSource cts;

            if (isTest)
            {
                cts = testcts;
            }
            else
            {
                cts = new CancellationTokenSource();
            }

            CancellationToken ct = cts.Token;


            if (isChildren)
            {
                InvokeActions(taskID, actions, ct);
            }
            else
            {
                var task = new Task(() =>
                {
                    try
                    {
                        OnActionsState?.Invoke(taskID, ActionInvokeStateType.Runing);
                        InvokeActions(taskID, actions, ct);
                    }
                    catch (OperationCanceledException)
                    {
                    }
                    catch (Exception e)
                    {
                        LogHelper.Error(e.ToString());
                    }
                    finally
                    {
                        OnActionsState?.Invoke(taskID, ActionInvokeStateType.Done);
                        cts.Dispose();
                    }
                }, ct);

                task.Start();
            }
        }
Beispiel #2
0
 public static void StopTestInvokeAction()
 {
     OnActionsState?.Invoke(TestTaskID, ActionInvokeStateType.Busy);
     testcts.Cancel();
 }