当前位置:编程学习 > C#/ASP.NET >>

MVC中的异步委托

    public delegate void writeHanlder(string str);

    public class UserController:BaseController
    { 

        private void writehandler(string s)
        {
            Console.WriteLine(s);
        }
        public UserController()
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
         
        public string test()
        {       
            try
            {
                writeHanlder hand = writehandler;
                hand.BeginInvoke("abcdefg", null, null);

                ErrorCode ec = new ErrorCode { codeKey = "user", codeValue = "2342", message = "ss" };
                return "OK";
        }

}
代码内部BeginInvoke方法执行之后确实立刻执行了 return "OK" 但浏览器还在继续等待 Console.WriteLine(s);执行才结束,如何做到浏览器立刻得到"OK"结果,而不是等待异步委托结束,求大神指点。。。不胜感激
PS:是否与HTTP请求无状态性有关, mvc 异步 delegate --------------------编程问答-------------------- IAsyncResult asyncResult = hand.BeginInvoke("abcdefg", null, null);
hand.EndInvoke(asyncResult);            --------------------编程问答-------------------- 这样似乎还是会等待执行Console.WriteLine(s);之后浏览器才能够得到"OK"结果 --------------------编程问答-------------------- 那简单

Thread t = new Thread(() => writehandler("abcdefg"));
t.Start();
ErrorCode ec = new ErrorCode { codeKey = "user", codeValue = "2342", message = "ss" };
return "OK";
补充:.NET技术 ,  Web Services
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,