Greetings!
I have created a progress bar via custom user controls and using Ajax
to update the bar status. I will then use the progress bar to show the
status of reports that take a while to run. In order to make this
work, I require that the report writing thread share its status with
other threads. Unfortunately I an running into locks with the session
state.
I am not including code to my progress bar user control because the
mechanics of it work fine. Where I believe I am having touble with is
the coding of the Ajax methods server side. I have been researching
this problem for several hours and have come to the conculsion that a
thread should be able to read the session object even though another is
writing.
In the following code I am referencing Ajax.dll. Here is my
javascript:
var req ;
var ID ;
var running = true;
function callme()
{
// Start the status refresh cycle.
ID = window.setTimeout("runloop()", 500) ;
// do postback
if (running) {
document.forms[0].submit();
running=false;
}
}
function runloop()
{
// Clear current time-out.
window.clearTimeout(ID) ;
// Get current progress bar status.
var currentTotalWidth =
document.getElementById("ProgressBar1").getAttribute("width");
var currentDone = currentTotalWidth -
document.getElementById("ProgressBar1Left").getAttribute("width");
// Get new status.
var response = WebForm1.ServerSideAdd();
// Set progress bar to new status.
var done = response.value;
var left = currentTotalWidth - done ;
document.getElementById("ProgressBar1Done").setAttribute("width",done)
;
document.getElementById("ProgressBar1Left").setAttribute("width",left)
;
// Check it again.
ID = window.setTimeout("runloop()", 500) ;
}
My HTML form contains ProgressBar1 user control and a button. The
onclick event of the button calls the callme() routine. In callme() I
start a cycle that checks the status then does a postback. The
postback launches a long-running routine.
Here is my server-side code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Ajax.Utility.RegisterTypeForAjax(GetType(WebForm1))
If IsPostBack Then
ServerJob()
End If
End Sub
<Ajax.AjaxMethodAttribute(Ajax.HttpSessionStateRequirement.Read)> _
Public Function ServerSideAdd() As Integer
Dim intTick As Integer
intTick =
Convert.ToDecimal(System.Web.HttpContext.Current.Session("Tick"))
Return intTick
End Function
Private Sub ServerJob()
Dim intTick As Integer
Do While intTick < 5
System.Threading.Thread.Sleep(1000)
intTick = intTick + 1
System.Web.HttpContext.Current.Session("Tick") = intTick
ProgressBar1.Value = intTick
Loop
End Sub
The ServerJob() routine launches on a postback. It runs 5 seconds and
updates Session variable Tick each second. The ServerSideAdd() routine
is called every half second by the cycle in Javascript. I want to read
the Session variable Tick and return to the client.
When I run my app and click the button, the page is frozen for 5
seconds. I know ServerSideAdd() is being called because I put an alert
on the return value in my javascript and it displays a 5 after
ServerJob() is done
What am I missing that will allow ServerSideAdd() to read Session
variables while ServerJob() is running?
Thx
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ajax.NET Professional" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/ajaxpro
The latest downloads of Ajax.NET Professional can be found at
http://www.ajaxpro.info
-~----------~----~----~----~------~----~------~--~---