0

I have a basic Asp.Net application, to test a problem I want two instances of IE calling an asp.net page, I want the first to block (Thread.Sleep) and the second to proceed, hence I have code like this:

private static bool firstOne = true;
...
if (firstOne)
{
    firstOne = false;
    System.Threading.Thread.Sleep(10000);
}

What I'm actually seeing is both pages wait for the sleep to finish, it's as if there is a single thread servicing both.

NB I don't have the debugger attached nor any breakpoints

This is on my work pc, default machine.config and web.config. Nothing unusual has been configured.

This isn't something I normally have to do so i could easily be missing something obvious here

Any ideas?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
tony
  • 2,178
  • 2
  • 23
  • 40
  • What web-server are you using to run the application? IIS, IIS Express, or the inbuilt Visual Studio web-server. – RB. Jan 24 '14 at 08:57
  • What does this have to do with Visual Studio? Also, ASP.NET code can't "sense" browser instances - only requests. – John Saunders Jan 24 '14 at 09:14
  • Just for info to help others, there were two separate IE instances but they were session sharing. To work around this create a shortcut and use -nomerge as the argument – tony Jan 24 '14 at 10:59

1 Answers1

1

The reason is the asp.net session module that locks the request until is finished.

Also the thread that you place on sleep is the requested thread and not a new one. If you make a new one and left the page return, then the new thread will live and die alone without affect your session. The session is lock on request the page, and unlock when the page is finished. The session is lock entire each request of the user to synchronize them. To avoid it you simply turn it off for that page, or use handlers that not use sessions by default.

You can also make your totally custom session that handle that case.

If you wondering if this is good, that session is lock your user, yes is good for starting sites because is really helps you to synchronize the user actions. If session not lock your user, you must do that by your self with mutexes, and on each action of your user, eg when you insert something on a database.

One similar question: Web app blocked while processing another web app on sharing same session

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150