Exemple #1
0
 //6 等待一个特定任务
 static async Task Worker6()
 {
     generator.children children = new generator.children();
     var A = children.tgo(() => Worker("A"));
     var B = children.tgo(() => Worker("B"));
     await children.wait(A);
 }
Exemple #2
0
        //7 超时等待一个特定任务,然后中止所有任务
        static async Task Worker7()
        {
            generator.children children = new generator.children();
            var A = children.tgo(() => Worker("A", 1000));
            var B = children.tgo(() => Worker("B", 2000));

            if (await children.timed_wait(1500, A))
            {
                Log("成功");
            }
            else
            {
                Log("超时");
            }
            await children.stop();
        }
Exemple #3
0
        //5 B、C任意一个执行完后,再执行A
        //B--
        //  |
        //  >-->A
        //  |
        //C--
        static async Task Worker5()
        {
            generator.children children = new generator.children();
            var B    = children.tgo(() => Worker("B", 1000));
            var C    = children.tgo(() => Worker("C", 2000));
            var task = await children.wait_any();

            if (task == B)
            {
                Log("B成功");
            }
            else
            {
                Log("C成功");
            }
            await Worker("A");
        }
Exemple #4
0
        private async Task Task1Action(int time)
        {
            WaitForm waitAction = new WaitForm();

            generator.children children  = new generator.children();
            generator.child    taskChild = children.tgo(async delegate()
            {
                bool cancelTask = false;
                Task task       = Task.Run(delegate()
                {
                    int ct = time / 100;
                    for (int i = 0; i < ct && !cancelTask; i++)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                });
                try
                {
                    await generator.wait_task(task);
                }
                catch (generator.stop_exception)
                {
                    cancelTask = true;
                    await generator.wait_task(task);
                }
            });
            children.go(async delegate()
            {
                await generator.sleep(500);
                await generator.send_control(this, delegate()
                {
                    waitAction.StartPosition = FormStartPosition.CenterParent;
                    waitAction.ShowDialog();
                });
                if (waitAction.isCancel)
                {
                    taskChild.stop();
                }
            });
            await children.wait(taskChild);

            waitAction.Close();
            await children.stop();
        }