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.
The way I have done things like this is:
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.