Example #1
0
        static void Main(string[] args)
        {
            //~preheat
            var t = Cmd.AsyncCallUse("Test001", null, new object[] { new Arg00 {
                                                                         A = 123
                                                                     } }, new UseEntry("use01", "sss"), new Business.Auth.Token {
                Key = "a", Remote = "b"
            });

            t.Wait();
            //~end

            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();

#if DEBUG
            var count = 1000;
#else
            var count = 100000;
#endif

            var results = new ConcurrentBag <int>();
            var tasks   = new ConcurrentBag <Task>();

            Parallel.For(0, count, c =>
            {
                var result = Cmd.CallUse("Test000", null, new object[] { new Arg00 {
                                                                             A = c
                                                                         } }, new UseEntry("use01", "abc"), new Business.Auth.Token {
                    Key = "a", Remote = "b"
                });

                results.Add(result.Data);

                var task = Cmd.AsyncCallUse("Test001", null, new object[] { new Arg00 {
                                                                                A = c
                                                                            } }, new UseEntry("use01", "abc"), new Business.Auth.Token {
                    Key = "a", Remote = "b"
                }).ContinueWith(c2 =>
                {
                    results.Add(c2.Result.Data);
                });

                tasks.Add(task);

                result = Cmd.CallIResultUse("Test002", null, new object[] { new Arg00 {
                                                                                A = c
                                                                            } }, new UseEntry("use01", "abc"), new Business.Auth.Token {
                    Key = "a", Remote = "b"
                });

                results.Add(result.Data);
            });

            Task.WaitAll(tasks.ToArray());

            watch.Stop();
            var total = Help.Scale(watch.Elapsed.TotalSeconds, 3);

            var dist = results.Distinct().OrderBy(c => c).ToList();

            Console.WriteLine($"ResultCount={results.Count} DistCount={dist.Count} Time={total}");
        }