//static dynamic Call(string cmd, params object[] args) //{ // var t = Cmd.AsyncCallGroup(cmd, null, args); // t.Wait(); // return t.Result; //} //static dynamic CallGroup(string cmd, string group, params object[] args) //{ // var t = Cmd.AsyncCallGroup(cmd, group, args); // t.Wait(); // return t.Result; //} static dynamic CallUse(string cmd, string group = null, object[] args = null, params object[] useObj) { var t = Cmd.AsyncCallUse(cmd, group, args, useObj); t.Wait(); return(t.Result); }
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}"); }