0

我有一个 asp.net 网页,它使用“backgroundworker”与一个做耗时工作的类进行交互。后台工作人员在网页中触发一个名为“worker_ProgressChanged”的例程。

这有效,我将报告的进度存储在会话变量中。

但现在我必须告诉我的网页进展情况。所以我做了以下。我在更新面板中放置了一个计时器,我希望它在代码隐藏中触发一个计时器事件。在那个计时器事件中,我想检索会话变量,并更新一个标签(也在更新面板中)没有后台工作人员,计时器确实会触发。但是对于后台工作人员,它不会。

关于进度事件触发的某些事情只是关闭了计时器触发或查找其事件处理程序的能力。

有人对此有想法吗?这是代码:

     <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

    <center>
    <table>
        <tr><td>
           <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" >
              <ContentTemplate>
              <asp:TextBox ID="TextBoxLog" runat="server" TextMode="MultiLine" Rows="5"  Width="550px" ReadOnly="true" Visible="false" BackColor="sandybrown"></asp:TextBox>
                  <asp:Timer ID="Timer1" runat="server" Interval="1000" Enabled="false"></asp:Timer><br />
                  <asp:Label ID="Labelerror2" SkinID="errorlabel" runat="server"  />
               </ContentTemplate>

           </asp:UpdatePanel>



            </td></tr>
        <tr><td>
            <asp:Label ID="Label1" runat="server" Text="Please enter the entire path of the video (on your PC) to upload to Azure" SkinID="ordinarylabel"></asp:Label></td></tr>
           <tr><td style="text-align:center">
               <asp:TextBox ID="TextBoxFileName" runat="server" Width="273px"></asp:TextBox>
               <asp:RequiredFieldValidator ID="RequiredFieldValidatorFilename"   ControlToValidate="TextBoxFileName" runat="server" Display="Dynamic"
                    ErrorMessage="Please enter a file name">*</asp:RequiredFieldValidator>


               </td></tr>
           <tr><td style="text-align:center">

               <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" ShowSummary="False" />

               <asp:Button ID="ButtonSubmit" runat="server" Text="Submit" />
               </td></tr>
    </table>
        <asp:Label ID="LabelError" SkinID="errorlabel" runat="server" EnableViewState="false" ClientIDMode="Static" />
         <asp:Label ID="LabelExperiment" SkinID="errorlabel" runat="server" EnableViewState="false" ClientIDMode="Static" />
        </center>

===================
Imports System.ComponentModel
Partial Class zOwner_UploadAzure
    Inherits System.Web.UI.Page

    Protected Sub ButtonSubmit_Click(sender As Object, e As EventArgs) Handles ButtonSubmit.Click
        Dim strName As String
        strName = Me.TextBoxFileName.Text.Trim

        If Not ClassStrings.IsValidFileName(strName, True) Then
            Me.LabelError.Text = "Error, the filename you supplied does not fit the Windows format of filenames."
            Exit Sub
        End If
        Me.TextBoxLog.Visible = True
        AzureNameSpaceGid.Azurex.userpcfilename = strName
        AzureNameSpaceGid.Azurex.username = Membership.GetUser.UserName
        Dim worker As BackgroundWorker = New BackgroundWorker()
        worker.WorkerReportsProgress = True
        AddHandler worker.DoWork, AddressOf AzureNameSpaceGid.Azurex.UploadFile

        AddHandler worker.ProgressChanged, New ProgressChangedEventHandler(AddressOf worker_ProgressChanged)
        Me.Labelerror2.Text = "Starting..."
        worker.RunWorkerAsync()
        Me.Timer1.Enabled = True
        Session("hitsubmit") = True
        '  AzureNameSpaceGid.Azurex.UploadFile(strName)
        '  Me.LabelError.Text = "The Upload to Azure is complete - <a href='addvideo500.aspx'>click here</a> to add the video to rateforsuccess."
    End Sub



    Private Sub worker_ProgressChanged(sender As Object, e As ProgressChangedEventArgs)
        Dim obj As Object
        obj = e.UserState
        Dim strMessage As String
        strMessage = obj.ToString
        If strMessage.StartsWith("URL_") Then
            Session("azureurl") = strMessage.Substring(4)
            Response.Redirect("addvideo500.aspx")
        ElseIf strMessage.StartsWith("LOGMESSAGE_") Then

            Session("strerror") = Session("strerror") & vbCrLf & "<br />" & strMessage.Substring(11)
        Else

            Session("strprogress") = Session("strprogress") & vbCrLf & strMessage
        End If

        ' LabelError.Text = ("Progress: " & e.ProgressPercentage.ToString() & "%")
    End Sub


    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        ' Response.AddHeader("cache-control", "no-cache")
        If Not Page.IsPostBack Then
            Session("hitsubmit") = False
            Session("strprogress") = ""
            Session("strerror") = ""
        End If
        If Session("hitsubmit") Then
            Me.Timer1.Enabled = True
            Me.TextBoxLog.Visible = True
        End If
    End Sub

    Protected Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Me.TextBoxLog.Text = Session("strprogress")
        Me.Labelerror2.Text = Session("strError")
        Me.LabelExperiment.Text = Me.LabelExperiment.Text & "***"
    End Sub
End Class
=======================

没有足够的空间放置实际的 azure 类。谢谢

4

0 回答 0