Recommendations for executing .NET HttpWebRequests in parallel in ASP.NET

后端 未结 4 1153
失恋的感觉
失恋的感觉 2021-01-13 04:37

I have an ASP.NET MVC web application that makes REST style web service calls to other servers. I have a scenario where I am making two HttpWebRequest calls to two separate

4条回答
  •  醉话见心
    2021-01-13 04:51

    I recommend that you create a worker class that does the HttpWebRequest and start it in its own thread for each connection. You can just Join the threads and wait until they both finish, or pass a callback method. In either case you need to account for connection failures, timeouts, and other exceptions. I prefer to use a callback that returns the connection result and the thread's ManagedThreadId, which I use to keep track of threads. The worker class should catch all exceptions so that you can handle them in the calling class.

    This article offers some insight and fixes for when you exceed the maximum number of connections: http://support.microsoft.com/kb/821268.

提交回复
热议问题