In a GET request, I run (something like):
public ActionResult Index(void) { webClient.DownloadStringComplete += onComplete; webClient.DownloadStringAsync(...); return null; }
I see that onComplete does not start until Index() . I see that onComplete is being called in another thread from one Index .
Question: Why is this happening? why does the webClient asynchronous thread seem to be blocked until the request processing thread ends?
Is there a way to fix this without starting a new thread from ThreadPool (I tried this and using the thread pool works as expected. Also, the WebClient callback is executed as expected if DownloadStringAsync is called from the ThreadPool thread).
ASP.NET MVC 3.0, .NET 4.0, MS Cassini dev Web Server (VS 2010)
EDIT: Here is the complete code:
public class HomeController : Controller { private static ManualResetEvent done; public ActionResult Index() { return Content(DownloadString() ? "success" : "failure"); } private static bool DownloadString() { try { done = new ManualResetEvent(false); var wc = new WebClient(); wc.DownloadStringCompleted += (sender, args) => {
multithreading asp.net-mvc
THX-1138
source share