protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); //清理日志 CreanFileHelper.Start(new CreanFileParam() { FileTimes = new List <FileTime>() { new FileTime() { DeleteTime = TimeSpan.FromSeconds(20), Directories = new List <string>() { $"{AppDomain.CurrentDomain.BaseDirectory}Logs" } } }, Log = ex => WriteHelper.Log(ex.ToString()), DueTime = TimeSpan.FromSeconds(5), Period = TimeSpan.FromSeconds(30) }); }
public void TestMethod4() { var list = new List <int>() { 6, 7, 8, 9, 4, 5, 1, 2, 3, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; //线程运行 var tasks = list.RunTask(p => { Thread.Sleep(p * 100); return(p); }); //返回线程状态 var row = new List <int>(); tasks.TaskStatus(80, (total, rs) => { WriteHelper.Log(total.ToString() + " : " + string.Join(";", rs)); row.AddRange(rs); }); var b = row.Distinct().Count() == 20; Assert.IsTrue(b); }
public void TestMethod7() { var list = new List <int>() { 6, 7, 8, 9, 4, 5, 1, 2, 3, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 100, 20 }; var nums = new List <int>(); var thread = new List <bool>(); list.RunTaskLimite(new TaskParam <int>() { Method = p => Thread.Sleep(p * 50), MaxThread = 3, Sleep = 0, Report = (type, start, end, item, n) => { WriteHelper.Log($"{start}-{end}:{type.GetReportTypeName()}{item}"); //验证是否全部完成 nums.Add(item); //验证最大线程数 thread.Add(end - start == 3); } }); var num = nums.Distinct().Count(); var b1 = thread.Exists(p => !p); Assert.IsTrue(num == list.Count && b1); }
private Task WriteLog(string name) { return(Task.Run(() => { for (var i = 0; i < 100; i++) { WriteHelper.Log($"{name}: 测试内容"); } })); }
public void TestMethod10() { var maxThread = 8; var list = new List <int>() { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 100, 100, 100, 100, 100, 100, 100, 100, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, }; var nums = new List <int>(); var threads = new List <bool>(); var rs = list.RunTaskLimite(new TaskParam <int, string>() { Method = p => { Thread.Sleep(p * 10); return(p.ToString()); }, MaxThread = maxThread, Sleep = 250, Report = (type, start, end, item, n) => { WriteHelper.Log($"{start}-{end}:{type.GetReportTypeName()}{item}"); //验证是否全部完成 nums.Add(item); //验证最大线程数 threads.Add(end - start <= maxThread); }, }); var num = nums.Distinct().Count(); var b1 = threads.Where(p => !p).ToList(); Assert.IsTrue(num == list.Distinct().Count(), $"执行数:{num}"); Assert.IsTrue(rs.Count == list.Count, $"执行数2:{rs.Count} {list.Count}"); Assert.IsTrue(b1.Count == 0, $"超出线程:{threads.Count}"); }
public void TestMethod1() { var sw = new Stopwatch(); sw.Start(); var ns = new NetSpeed(); sw.Stop(); WriteHelper.Log($"初始化耗时:{sw.ElapsedMilliseconds}ms"); for (var i = 0; i < 5; i++) { sw.Restart(); var sent = ns.GetSentSpeed(); var revice = ns.GetReceivedSpeed(); sw.Stop(); WriteHelper.Log($"接收:{revice}kb;发送:{sent}kb;耗时:{sw.ElapsedMilliseconds}ms"); Thread.Sleep(1000); } }