get updated session variable in a saperate request while first request in progress

AmitChotaliya

New member
Joined
May 16, 2013
Messages
1
Programming Experience
Beginner
Hi All,I have a page on which there is a link, when clicked it makes a server call to handler using jquery ajax to start zip creation of a list of files. that click also strats a repeatative server calls which checks what is the current zip creation process.The logic is simple, I have stored totalBytes in session which is sum of size of all the files, and I have another variable named processedBytes in the session which holds sum of files processed, I make server call every second and get (processedBytes / totalBytes * 100) from session which is percentage of process completed. but in current implementation it always returns 0 until and unless the zip creation is completed.The zip creation method and the zip progress method are in the same handler, differently called using different paramters.I don't know why it is not working. I have the same implementation in java and php they both seem to be working fine.Here some shortened code.
VB.NET:
[/FONT][/COLOR][/LEFT][COLOR=#000000]<%[/COLOR][COLOR=#000000]@ WebHandler Language="VB" Class="Handler" %>

Imports System
Imports System.Web

Public Class Handler : Implements IHttpHandler, IRequiresSessionState

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        'method call depeding on parameter received from browser
        If (context.Request.Params.Get("method").Equals("createZip")) Then
            CreateZip(context)
        Else
            ZipProgress(context)
        End If
    End Sub
 
    Public Sub CreateZip(ByRef context As HttpContext)
        ' assume that this is populated with some file paths
        Dim files As ArrayList = New ArrayList
        context.Session("totalBytes") = 2048 'this value will be populated by iterating through all the files and adding size
        context.Session("processedBytes") = 0
        'will loop through files and add them into a zip
        For Each file As String In files
            'code to add individual file in a zip
            context.Session("processedBytes") = context.Session("processedBytes") + 1 ' this value is size of current file added to the zip
        Next
    End Sub
    
    Public Sub ZipProgress(ByRef context As HttpContext)
        'this is processed bytes percentage of total bytes
        context.Response.Write(context.Session("processedBytes") * context.Session("totalBytes") / 100)
    End Sub
  
End Class[/COLOR][LEFT][COLOR=#222222][FONT=Segoe UI]

In this code let's assume that ZipCreate method takes about 15 minutes to zip all the files but it keeps updating the processedBytes as soon as it adds a file in the zip with it's size.
I will keep calling the ZipProgress using ajax every second to check the progress of zip creation by checking the processedBytes session variable. that is where the problem occures if I debug processedBytes variable in ZipCreate method it prints correct value but if I print same in ZipProgress method it always prints 0. so the method always returns progress as 0 untill the zip progress method is completed.I could send original code if required.
 
Back
Top