7

次のコードがあり、経過ミリ秒が不正確であるようです:

    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();
    }

これは正しいように見えますか、それとも痛々しいほど明らかな何かが欠けていますか?

4

1 に答える 1

0

これは私にはまったく問題ないように見えます。

Repository.GetAll メソッドが非同期でない場合、エラーが発生する可能性があります。うまくいけば、次のような署名があります。

    public async Task<IEnumerable<Account>> GetAll();
于 2015-08-26T05:28:38.493 に答える