Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
Send the current state of a long process while it's running

I'd like to know if there is a way in ASP.NET C# to somehow show to the user that the work is still going while executing something that take ages to end.

Let me explain a bit more with some code. First I have a ASPX page that show some fileUpload items and a button to send the form to the server. It allows the user to send 3 differents file that are each processed differently :

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="MassUpdates.aspx.cs" Inherits="MassUpdates" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <h3 style="font: bold;">Mass Updates</h3>
    <hr />
    <div class="row">
        <div class="col-12 mb-2">
            <asp:Label ID="Label0" runat="server" Text="File 1 : "></asp:Label>
            <asp:FileUpload ID="fup1" runat="server" />
        </div>
        <div class="col-12 mt-2 mb-2">
            <asp:Label ID="Label1" runat="server" Text="File 2 : "></asp:Label>
            <asp:FileUpload ID="fup2" runat="server" />
        </div>
        <div class="col-12 mt-2 mb-2">
            <asp:Label ID="Label2" runat="server" Text="File 3 : "></asp:Label>
            <asp:FileUpload ID="fup3" runat="server" />
        </div>
    </div>
    <div class="row">
        <div class="col-12 mt-2">
            <asp:Button ID="btnEnvoi" runat="server" Text="Envoyer" OnClick="btnEnvoi_Click" />
        </div>
        <div class="col-12 mt-2">
            <asp:Label ID="lblMsg" runat="server" Text="" Visible="false"></asp:Label>
        </div>
    </div>
</asp:Content>

Then, on the code behind page, I have a tiny function called when the user press the button that call every file process if the file has been dropped :

protected void btnSend_Click(object sender, EventArgs e)
{
    if (fup1.HasFiles)
    {
        result += trtFile1(); // Return a string that give the final feedback of the execution for File 1
    }

    if (fup2.HasFiles)
    {
        result += trtFile2(); // Return a string that give the final feedback of the execution for File 2
    }

    if (fup3.HasFiles)
    {
        result += trtFile3(); // Return a string that give the final feedback of the execution for File 3
    }

    lblMsg.Text = result;
}

But as I said earlier, if the user sends 3 huge files, doing all the process take years (it's a picture) and they wonder if the application as crashed or is still running.

What I want to know, is if there is a way to send to the client side page some informations (like a text or a value to set in a progress bar) when we reached a step on the function. Something like that :

protected void btnSend_Click(object sender, EventArgs e)
{
    if (fup1.HasFiles)
    {
        // Send to the client that we start file 1
        result += trtFile1(); // Return a string that give the final feedback of the execution for File 1
    }

    if (fup2.HasFiles)
    {
        // Send to the client that we start file 2
        result += trtFile2(); // Return a string that give the final feedback of the execution for File 2
    }

    if (fup3.HasFiles)
    {
        // Send to the client that we start file 3
        result += trtFile3(); // Return a string that give the final feedback of the execution for File 3
    }

    lblMsg.Text = result;
}

Thanks if anyone of you already heard about this kind of functionality or has something similar in his pocket !

Rolstyam.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The way I have done things like this is:

  1. Client makes a request, including a Guid to serve as a key for progress reporting
  2. Server starts processing, and periodically updates some shared data structure with the progress, using the Guid as key.
  3. Client uses a timer to periodically poll the server for progress, again using the guid as key.
  4. When the server completes the processing it should remove the guid from the shared storage to prevent any memory leaks.

I have no idea if this is the "correct" way to do it, only that it worked well enough for my purpose, i.e. an application backend doing processing intensive work. If there is a better way I hope someone will post it. I do not know how applicable it is if downloading data is the major bottleneck, nor how difficult it would be to use for a webpage.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda