Don't understand using UpdatePanel/progress bar with long-running processes

row118

Member
Joined
Feb 4, 2006
Messages
21
Programming Experience
5-10
This code behind emulates a user choosing 3(could be up to 10) reports and hitting submit button on the web interface. I don't know how to complete the code to execute parameterized batch file using an UpdatePanel and/or background-workers.

VB.NET:
Imports System.IO

Partial Class UpdatePanel
    Inherits System.Web.UI.Page
  
    Dim arrRptQueue As New ArrayList
  
    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim fi As FileInfo

        For Each oRpt As ReportObject In arrRptQueue
            If Not oRpt.finished Then
                fi = New FileInfo(oRpt.reportFile)
                If fi.Exists Then
                    'Replace PLEASE WAIT message with hypelink to report 
                    'or preferably replace ajax-loading.gif with hyperlink to report
                    Label1.Text = String.Format("<a href=""{0}"">{1}</a>", oRpt.reportFile, oRpt.reportname)
                End If
            End If
        Next oRpt
    End Sub

    Public Sub ExecuteBatchfile(ByVal filename As String, ByVal param As String)
        Dim objProcess As System.Diagnostics.Process
        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.FileName = filename
            objProcess.StartInfo.Arguments = param
            objProcess.Start()
            objProcess.Close()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim oRpt1 As New ReportObject(100, "Daily  Report", "c:\temp\daily_12312010.txt")
        Dim oRpt2 As New ReportObject(101, "Weekly Report", "c:\temp\weekly_12312010.txt")
        Dim oRpt3 As New ReportObject(102, "Annual Report", "c:\temp\yearly_12312010.txt")
        With arrRptQueue
            .Add(oRpt1)
            .Add(oRpt2)
            .Add(oRpt3)

            For Each oRpt As ReportObject In arrRptQueue
                ExecuteBatchfile(oRpt.reportFile, oRpt.reportname)
            Next oRpt
        End With

    End Sub
End Class

Public Class ReportObject
    Public reportnbr As Int16 = 0
    Public reportname As String = ""
    Public reportFile As String = ""
    Public finished As Boolean = False

    ' notation for parameter
    Public Sub New(ByVal pReportnbr As Int16, ByVal pReportName As String, ByVal pReportFile As String)
        reportnbr = preportnbr
        reportname = pReportName
        reportFile = pReportFile
    End Sub
End Class

ASPX. I need something like this for ASPX page.
This was inspired by : Walkthrough: Using the ASP.NET Timer Control with Multiple UpdatePanel Controls. Achieves objective of multiple controls being update based on same trigger.

VB.NET:
  <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000">
            </asp:Timer>
        </div>
        <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="UpdatePanel1 not refreshed yet."></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
            <ContentTemplate>
                <asp:Label ID="Label2" runat="server" Text="UpdatePanel2 not refreshed yet."></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>

      <asp:UpdatePanel ID="UpdatePane3" UpdateMode="Conditional" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
            <ContentTemplate>
                <asp:Label ID="Label3" runat="server" Text="UpdatePanel3 not refreshed yet."></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>

    </form>

simulate_process.bat
VB.NET:
@echo off
echo.simulating process to create report: %~1  which can takes up to 5 minutes
@choice /T 10 /C y /CS /D y > nul    	
echo.FileContents > %~1


Should i dynamically add update panels or drag and drop 5 updatepanels onto page and limit user to choosing 5 reports? I welcome working ode examples.
 
Back
Top