如何将同步方法更改为异步方法? [英] How Do I change my Synchronous Methods to Asynchronous Methods?

查看:469
本文介绍了如何将同步方法更改为异步方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如何将我的代码集更改为异步?



这是我的代码:

Hi Everyone,

How would I change my set of code to asynchronous?

Here's my code:

public class ReportController : Controller
    {
        //
        // GET: /Report/
        //*** Daily Sales Report (Summary)
        public ActionResult DailySalesReport()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult GetDailySalesReport(String date)
        {
            CommReportManager commReportManager = new CommReportManager();
            var dailySalesReport = commReportManager.GetDailySalesReport(date);
            return Json(dailySalesReport);
        }
}





非常感谢您的时间。



Thank You very much for your time.

推荐答案

试试这个



Try this

public async Task<ActionResult> GetDailySalesReport(String date)
{
    ViewBag.SyncOrAsync = "Asynchronous";
    var gizmoService = new GizmoService();
    return View("Gizmos", await gizmoService.GetGizmosAsync());

    CommReportManager commReportManager = new CommReportManager();
    var dailySalesReport = commReportManager.GetDailySalesReport(date);
    return await Json(dailySalesReport);

}


这篇关于如何将同步方法更改为异步方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆