asp.net mvc3 异步执行

public void IndexAsync()
        {
            AsyncManager.OutstandingOperations.Increment(2);
            Task.Factory.StartNew(() => {
                string url = "http://www.cnblogs.com";
                WebClient client = new WebClient();
                string reply=client.DownloadString(url);
                System.Threading.Thread.Sleep(10000);
                AsyncManager.Parameters["data"] = reply;
                AsyncManager.OutstandingOperations.Decrement();
            
            });
            
            Task.Factory.StartNew(() => {
                string url = "http://s.189180.net";
                WebClient client = new WebClient();
                string reply = client.DownloadString(url);

                System.Threading.Thread.Sleep(10000);

                AsyncManager.Parameters["data"] = reply;
                AsyncManager.OutstandingOperations.Decrement();
            
            });
        }

        public ActionResult IndexCompleted(string data, string moredata)
        {
            Operations translations = new Operations() { FirstOperation = "Data", SecondOperation = "moredata" };
            return View(translations);
        }

posted @ 2013-02-03 21:16  bert.zeng  阅读(204)  评论(0编辑  收藏  举报