public async static void testy() { // call method. var result = _client.SumAsync(100, 200).ResponseAsync.Result; Console.WriteLine("客户端结果:" + result); result = _client.SumAsync(190, 200).ResponseAsync.Result; Console.WriteLine("客户端结果:" + result); result = _client.SumAsync(10, 290).ResponseAsync.Result; Console.WriteLine("客户端结果:" + result); result = _client.SumAsync(65, 233).ResponseAsync.Result; Console.WriteLine("客户端结果:" + result); }
public async void StartAccess() { for (int n = 0; n < 10; n++) { var ret = client.SumAsync(100, n); Debug.WriteLine(@"result = {0}", ret.ResponseAsync.Result); } var dt = client.GetFittingTable(); foreach (DataRow dr in dt.Rows) { Debug.WriteLine(dr[0].ToString()); } }
static async Task UnaryRun(IMyFirstService client) { try { var vvvvv = await await client.SumAsync(10, 20); Console.WriteLine("SumAsync:" + vvvvv); var v2 = await client.SumAsync2(999, 1000); Console.WriteLine("v2:" + v2); } catch (Exception ex) { Console.WriteLine(ex); } }
static async Task UnaryLoadTest(IMyFirstService client) { const int requestCount = 100000; ThreadPool.SetMinThreads(1000, 1000); var sw = Stopwatch.StartNew(); Task[] t = new Task[requestCount]; for (int i = 0; i < requestCount; i++) { t[i] = (client.SumAsync(i, i).ContinueWith(y => y.Result.ResponseAsync).Unwrap()); } await Task.WhenAll(t); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds + "ms"); // 10000request, x-ms var one = sw.Elapsed.TotalMilliseconds / requestCount; // 1request, ms Console.WriteLine(one); Console.WriteLine((1000.0 / one) + "req per/sec"); }