Page_Load serialized?

A

ajholme

We have a problem in our application: if a user clicks a link to load
another page before the previous ASPX has finished executing, the Sub
New() constructor of the second page executes immediately, but its
Page_Load() event is not fired until the previous ASPX has finished.
I've reproduce this outside our applciation using two almost identical
pages Test1.aspx and Test2.aspx as follows:

----------------------------------------------------------

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Test1.aspx.vb" Debug="False" Trace="False"
Inherits="UserInterface.Web.CTest1" %>

<html>
<head></head>
<body>

<h1>Test1</h1>

Before ... <%Snooze()%> After

</body>
</html>

----------------------------------------------------------

Public Class CTest1

Inherits System.Web.UI.Page

Public Sub New()
System.Diagnostics.Debug.WriteLine("Test1 New")
End Sub

Public Overridable Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
System.Diagnostics.Debug.WriteLine("Test1 Page_Load")
end sub

Public Sub Snooze()
System.Diagnostics.Debug.WriteLine("Test1 Snooze --->")
System.Threading.Thread.Sleep(10000)
System.Diagnostics.Debug.WriteLine("Test1 Snooze <---")
End Sub

End Class
 
P

Phillip Ian

Have you tried it using some other way of implementing Snooze? I'm not
sure, but I think you might be putting the entire asp_wp process to
sleep, which would stop your second page (and the whole of asp.net)
from running.
 
A

ajholme

Phillip said:
Have you tried it using some other way of implementing Snooze? I'm not

We don't call Sleep() in our application; we have a slow database
query.
sure, but I think you might be putting the entire asp_wp process to
sleep, which would stop your second page (and the whole of asp.net)
from running.

Other sessions are not affected.
 
S

Scott Allen

Right, sleep only pauses the current request.

Page_Load is not serialized, but concurrent requests to a specific
instance of Session state are serialized - if those requests intend to
change Session state.

You can set EnableSessionState="false" in the @ Page directive to
avoid the serialization. EnableSessionState="ReadOnly" will also
change the behavior you see, because the runtime uses a reader /
writer lock, and multiple readers are allowed in.

HTH,
 
A

ajholme

We have a problem in our application: if a user clicks a link to load
another page before the previous ASPX has finished executing, the Sub
New() constructor of the second page executes immediately, but its
Page_Load() event is not fired until the previous ASPX has finished.

http://msdn2.microsoft.com/library/ms178581(en-us,vs.80).aspx

says:

Concurrent Requests and Session State
Access to ASP.NET session state is exclusive per session. That is, if
two different users make concurrent requests, then access to each
separate session is granted concurrently. However, if two concurrent
requests are made for the same session (that is, using the same
System.Web.SessionState.HttpSessionState.SessionID value), then the
first request received gains exclusive access to the session
information and the second request will execute once the first request
completes. If the
System.Web.Configuration.PagesSection.EnableSessionState page directive
is set to ReadOnly, then a request for the read-only session
information does not result in an exclusive lock of the session data.
Read-only requests for session data may still have to wait for a lock
gained by a read-write request for session data to clear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top