使用StopWatch类测量C#/异步数据访问
发布时间:2020-12-15 07:50:53 所属栏目:百科 来源:网络整理
导读:我有以下代码,似乎Elapsed Milliseconds不准确: public async TaskActionResult Index() { try { var connString = RoleEnvironment.IsEmulated ? ConfigurationManager.ConnectionStrings["Poc"].ConnectionString : ConfigurationManager.ConnectionStrin
我有以下代码,似乎Elapsed Milliseconds不准确:
public async Task<ActionResult> Index() { try { var connString = RoleEnvironment.IsEmulated ? ConfigurationManager.ConnectionStrings["Poc"].ConnectionString : ConfigurationManager.ConnectionStrings["PocVm"].ConnectionString; var repository = new AccountRepository(connString); var stopWatch = new Stopwatch(); stopWatch.Start(); var accounts = await repository.GetAll(); stopWatch.Stop(); ViewBag.Accounts = accounts; ViewBag.VmStatus = stopWatch.ElapsedMilliseconds; } catch (Exception e) { blah blah blah... } return View(); } 这看起来是正确的还是我错过了一些非常明显的东西? 解决方法
这对我来说完全没问题.
如果Repository.GetAll方法不是异步的话,可能会出现错误,希望它有这样的签名: public async Task<IEnumerable<Account>> GetAll(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |