private void button1_Click(object sender, EventArgs e) { Task.Run(() => { Log("开始"); try { List <CARINFO_MERGE> list = CacheUtil.TryGetValue <List <CARINFO_MERGE> >("CARINFO_MERGE", () => { using (var session = DBHelper.GetSession()) { string sql = "select * from CARINFO_MERGE where rownum<20000"; LogTimeUtil logTime = new LogTimeUtil(); List <CARINFO_MERGE> result = session.FindListBySql <CARINFO_MERGE>(sql); Log(logTime.LogTime("耗时")); return(result); } }); Log("结束"); } catch (Exception ex) { Log(ex.Message + "\r\n" + ex.StackTrace); } }); }
private void btnLogTime_Click(object sender, EventArgs e) { Task.Run(() => { LogTimeUtil log = new LogTimeUtil(); Thread.Sleep(500); log.LogTime("等待1", true); Thread.Sleep(600); log.LogTime("等待2", true); Thread.Sleep(300); log.LogTime("等待3"); }); }