asp.net mvc 2 multithread
Posted
by Chris Cap
on Stack Overflow
See other posts from Stack Overflow
or by Chris Cap
Published on 2010-05-19T18:58:17Z
Indexed on
2010/05/19
19:00 UTC
Read the original article
Hit count: 185
asp.net-mvc
|ASP.NET
I'm getting some weird behavior in asp.net MVC2 (at least it's not what I'm expecting). I have a controller httppost action that processes credit cards. I'm setting a session variable on the server to let me know if a user has attempted to process a card. I clear that session variable when I'm done. I am doing some very quick posts to test the process and the session variable is coming back null everytime because I clear the session variable at the end of the process. I have some debug prints that show me that the all requests are processed synchronously. That is...the first attempt occurs, it fails, session variable is cleared, second attempt tries and fails and the variable is cleared, etc... My first thought was that this was a side effect of debugging and that it just lined requests up for debugging purposes using the local webserver. So I put it on a development server and the same thing is occurring. Multiple submits/posts are processed synchronously. I even put a System.Threading.Sleep in there to make sure it would stop right after I set the session variable and it still won't even START the second request until the first is done.
Has anyone else seen this behavior? My understanding was that a worker process was spawned for each request and that these actions could happen asychronously.
Here's some psuedo code
if (Session["CardCharged"] != null)
return RedirectToAction("Index", "Problem");
Session["CardCharged"] = false; //starting the process
System.Threading.Thread.Sleep(10000);
//charge card here
if (!providerResponse.IsApproved)
{
System.Diagnostics.Debug.WriteLine("failed");
Session["CardCharged"] = null; //have to allow them to charge again since this failed
return View(myModel);
}
Session["CardCharged"] = true;
return RedirectToAction("Index", "OrderComplete");
I should mention that my code ALWAYS fails the credit card check for testing purposes. I'm trying to test the situation where processing is STILL occurring and redirect the user elsewhere. I have set a dummy session variable elsewhere to assure that the session id "sticks". So I know the session id is the same for each request.
Thanks
© Stack Overflow or respective owner