static void SocketTest() { int count = 1000; int port = 11111; Stopwatch watch = new Stopwatch(); TcpSocketServer server = new TcpSocketServer(port); server.HandleRecMsg = (a, b, c) => { b.Send(c); }; server.StartServer(); watch.Start(); LoopHelper.Loop(count, () => { //AutoResetEvent waitEvent = new AutoResetEvent(false); TcpSocketClient tcpSocketClient = new TcpSocketClient(port); tcpSocketClient.HandleRecMsg = (a, b) => { Console.WriteLine($"收到时间:{DateTime.Now.ToString("HH:mm:ss:ffffff")}"); //waitEvent.Set(); }; tcpSocketClient.StartClient(); Console.WriteLine($"发送时间:{DateTime.Now.ToString("HH:mm:ss:ffffff")}"); tcpSocketClient.Send(new byte[] { 0X01 }); //waitEvent.WaitOne(); Thread.Sleep(1000); }); watch.Stop(); Console.WriteLine($"每次耗时:{(double)watch.ElapsedMilliseconds / count}ms"); }
public ActionResult GetChartData() { double length = 0; LinkedList <double> pointList = new LinkedList <double>(); List <double> rate = new List <double>(10); LoopHelper.Loop(10, () => { rate.Add(0); }); double minutes = 60; double count = 10.0 * 60 * 1000000 / 10; for (double i = 0; i < count; i++) { double s = 0.5861 * 1; length = length + s; double x = 0; if ((length / 20) % 1 < 0.5) { x = length % 10; } else { x = 10 - (length % 10); } rate[(int)x]++; } List <string> xData = new List <string>(); List <double> yData = new List <double>(); rate.ForEach((aValue, index) => { xData.Add((index + 0.5).ToString()); yData.Add(aValue); }); var resData = new { XData = xData, YData = yData }; return(Content(resData.ToJson())); }
static void RpcTest() { int port = 9999; int count = 1; int errorCount = 0; RPCServer rPCServer = new RPCServer(port); rPCServer.HandleException = ex => { Console.WriteLine(ExceptionHelper.GetExceptionAllMsg(ex)); }; rPCServer.RegisterService <IHello, Hello>(); rPCServer.Start(); IHello client = null; client = RPCClientFactory.GetClient <IHello>("127.0.0.1", port); client.SayHello("aaa"); Stopwatch watch = new Stopwatch(); List <Task> tasks = new List <Task>(); watch.Start(); LoopHelper.Loop(1, () => { tasks.Add(Task.Run(() => { LoopHelper.Loop(count, () => { string msg = string.Empty; try { msg = client.SayHello("Hello"); Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}:{msg}"); } catch (Exception ex) { Console.WriteLine(ExceptionHelper.GetExceptionAllMsg(ex)); } }); })); }); Task.WaitAll(tasks.ToArray()); watch.Stop(); Console.WriteLine($"每次耗时:{(double)watch.ElapsedMilliseconds / count}ms"); Console.WriteLine($"错误次数:{errorCount}"); }
static void Main(string[] args) { Base_UserBusiness base_UserBusiness = new Base_UserBusiness(); List <Base_User> insertList = new List <Base_User>(); LoopHelper.Loop(20, index => { insertList.Add(new Base_User { Id = GuidHelper.GenerateKey(), UserId = GuidHelper.GenerateKey(), UserName = $"名字{index}", RealName = $"名字{index}" }); }); base_UserBusiness.Insert(insertList); Console.WriteLine("完成"); Console.ReadLine(); }