ContinueWith在本地主机上正常工作但在服务器端无法正常工作

时间:2018-05-30 06:22:05

标签: c#

我正在尝试在C#中使用ContinueWith,但它在服务器端无法正常工作,但在localhost正常工作期间

            string APIAutoEmailUrl = ConfigurationManager.AppSettings["AutoEmailAPIUrl"].ToString();
            string SoAUrl = APIAutoEmailUrl + "/SendSOA";
            string PriorUrl = APIAutoEmailUrl + "/SendPriorNotification";
            string PostUrl = APIAutoEmailUrl + "/SendPostNotification";

            ASCIIEncoding encoding = new ASCIIEncoding();
            HttpWebRequest SoARequest = (HttpWebRequest)WebRequest.Create(SoAUrl);
            SoARequest.Method = "Post";
            SoARequest.ContentLength = 0;
            SoARequest.ContentType = "application/json";
            var SoA = SoARequest.GetResponseAsync(); //Mohan: Method will not wait for response just trigger and forget

            SoA.ContinueWith(Prior =>
            {
                //Mohan: It will complete first task then it will do second task
                ASCIIEncoding encodingPrior = new ASCIIEncoding();
                HttpWebRequest PriorRequest = (HttpWebRequest)WebRequest.Create(PriorUrl);
                PriorRequest.Method = "Post";
                PriorRequest.ContentLength = 0;
                PriorRequest.ContentType = "application/json";
                var PriorNotification = PriorRequest.GetResponseAsync(); //Mohan: Method will not wait for response just trigger and forget

                PriorNotification.ContinueWith(Post =>
                {
                    //Mohan: It will complete first and Second task then it will do Third task
                    ASCIIEncoding encodingPost= new ASCIIEncoding();
                    HttpWebRequest PostRequest = (HttpWebRequest)WebRequest.Create(PostUrl);
                    PostRequest.Method = "Post";
                    PostRequest.ContentLength = 0;
                    PostRequest.ContentType = "application/json";
                    var PostNotification = PostRequest.GetResponseAsync(); //Mohan: Method will not wait for response just trigger and forget
                });
            });

第一个和第二个任务在服务器端执行,但第三个任务不是在服务器端执行,而是在本地主机正常工作期间。

0 个答案:

没有答案
相关问题