I'm attempting to monitor the progress of a file upload by comparing the
Request.TotalBytes and Request.ContentLength via a timer event in an HTTP
Module. It seems to be locking up. Am I on the right track? Will the
timer work with the HTTP Module in this fashion, or does the module
interfer with the file being uploaded. The code is attached. Thanks for
any help/suggestions!
---------------
Imports System.Web
Public Class progressModule
Implements IHttpModule
Dim pHandler As ProgressHandler
Dim context As HttpContext
Dim currentId As String
Dim timer As Timers.Timer
Public Sub Init(ByVal Application As Web.HttpApplication) Implements
IHttpModule.Init
AddHandler Application.BeginRequest, AddressOf
Me.Application_BeginRequest
AddHandler Application.EndRequest, AddressOf
Me.Application_EndRequest
AddHandler Application.Error, AddressOf Me.Application_Error
End Sub
Public Sub Dispose() Implements IHttpModule.Dispose
timer = Nothing
End Sub
Private Sub Application_Error(ByVal source As Object, ByVal e As
EventArgs)
Dim application As HttpApplication = CType(source, HttpApplication)
If Not currentId Is Nothing Then
pHandler.SetError(currentId, application.Server.GetLastError())
End If
End Sub
Private Sub Application_BeginRequest(ByVal source As Object, ByVal e
As EventArgs)
Dim application As HttpApplication = CType(source, HttpApplication)
context = application.Context
currentId = context.Request.QueryString("Id")
If Not currentId Is Nothing Then
pHandler = New ProgressHandler
timer = New Timers.Timer(1500)
AddHandler timer.Elapsed, AddressOf OnTimerTick
timer.Start()
pHandler.UpdateValues(currentId, context.Request.TotalBytes,
context.Request.ContentLength)
End If
End Sub
Private Sub Application_EndRequest(ByVal source As Object, ByVal e As
EventArgs)
Dim application As HttpApplication = CType(source, HttpApplication)
Dim context As HttpContext = application.Context
If Not currentId Is Nothing Then
timer.Stop()
timer.Close()
End If
End Sub
Private Sub OnTimerTick(ByVal source As Object, ByVal e As
Timers.ElapsedEventArgs)
pHandler.UpdateValues(currentId, context.Request.TotalBytes,
context.Request.ContentLength)
End Sub
End Class