4

我有点碰壁了,我有一段代码,多线程发出网络请求

 var request = (HttpWebRequest)WebRequest.Create(uri) as HttpWebRequest;
                    request.Accept = "application/xml";
                    request.Method = shopfiyRequest.ActionType.ToString();
                    if (string.IsNullOrEmpty(shopfiyRequest.ContentType))
                        request.ContentType = shopfiyRequest.ContentType;

                    // authentication
                    var cache = new CredentialCache();
                    cache.Add(uri, "Basic", new NetworkCredential(apiKey, password));
                    request.Credentials = cache;

                    ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);


HttpWebResponse response = null;

                        Log.Debug("Getting responsce from shopify");
                        // This is where the HTTP GET actually occurs.
                        response = (HttpWebResponse)request.GetResponse();

一旦线程到达该行response = (HttpWebResponse)request.GetResponse();,它就会抛出以下异常

无法计算表达式,因为代码已优化或本机框架位于调用堆栈顶部。

我试过捕捉和忽略中止异常,但似乎无济于事

任何帮助或在这方面的帮助都将是可观的。

4

0 回答 0