C# 网页中的异步是不是只能用ajax来请求啊?我用BeginInvoke这种异步请求会出错..

我用异步请求的代码如下,运行的时候会出错,怎么写才正确呢?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Runtime;

namespace WebApplication2
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Test t = new Test(T);
            t.BeginInvoke(new AsyncCallback((Ir) => {Response.Write("eeeeeeee"); }), null);
            Response.Write("dddddddd");
            
        }
        private void T()
        {
            Thread.Sleep(10000);
            
        }
        delegate void Test();
    }
    
}

 

另外,在web编程中多线程是不是基本都用不上?都是用ajax来请求的呢?

谢谢指导!

BIG阳
浏览 316回答 2
2回答

蝴蝶刀刀

你写的那个是在服务器端的异步操作,我们一边说的异步,都是指的客户端通过ajax,异步的去取得服务器端的数据,也就是指的,页面不刷新
打开App,查看更多内容
随时随地看视频慕课网APP