Пример #1
0
        public static async Task DoCombinedSync(this MyComponent parent,
                                                string name)
        {
            // calculate access Scope
            long scope = 3;

            await parent.InChild(scope, async component =>
            {
                await component.DoA(name + ".1");
                await component.DoB(name + ".2");
            });
        }
Пример #2
0
        public static Task DoCombined(this MyComponent parent,
                                      string name)
        {
            // calculate access Scope
            long scope = 3;

            return(TaskCollector.With(tc =>
            {
                parent.InChild(scope, component =>
                {
                    tc.Add(component.DoA(name + ".1"));
                    tc.Add(component.DoB(name + ".2"));
                });
            }));
        }
        private static async Task run()
        {
            Console.WriteLine("\nasynchronous test");
            DateTime start = DateTime.Now;
            await TaskCollector.With(tc =>
            {
                using (var comp = new MyComponent("test component 1"))
                {
                    tc.Add(comp.DoC("t0"));
                    tc.Add(comp.DoA("t1"));
                    tc.Add(comp.DoB("t2"));
                    tc.Add(comp.DoCombined("t3"));
                    tc.Add(comp.DoB("t4"));
                    tc.Add(comp.DoC("t5"));
                }
            });

            Console.WriteLine($"duration: {DateTime.Now - start}");

            Console.WriteLine("\nsynchronous test");
            start = DateTime.Now;
            using (var comp = new MyComponent("test component 2"))
            {
                await comp.DoC("t0");

                await comp.DoA("t1");

                await comp.DoB("t2");

                await comp.DoCombinedSync("t3");

                await comp.DoB("t4");

                await comp.DoC("t5");
            }
            Console.WriteLine($"duration: {DateTime.Now - start}");
        }