Write multiple text lines while the page is performing a lengthy task

I am writing a page asp.netthat prints the text as follows:

protected void Page_Load(object sender, EventArgs e)
{
    Response.ClearContent();
    for (int i = 0; i <=100; i++)
    {   
        var isOk = DoSomeTask(i);
        context.Response.Write(string.Format("Step {0}: {1}",i, isOk ? "Success": "Error"));
        Thread.Sleep(4000);
    }
}

I have a problem, the text is displayed only when the page loads successfully. How to render text at runtime?

+4
source share
5 answers

It is good that I read your question quite early, but did not answer, because I was afraid that I could not give you recommendations on a compressed code sample. You will encounter the same obstacles with both AJAXhandlers ( ashx) and both are pretty similar.

- , , , .

- -, asp.net SignalR - ! here.

:

  • , ,
  • setup signalr (), , 1.
  • aspx ( ) signalr
  • ( 2) ( setp 3) yuor.

signalr

+1

, ASP.NET, Page_load . , , Ajax ASP.NET.

https://msdn.microsoft.com/en-us/library/ms178472.aspx

. , , . , , . . " ", , ViewState PostData ASP.NET, .

Pre Render: . , , , , , . , , HTML.

: , ViewState PostData.

0

, -, , , , .

, . :

telnet localhost 80 (substitute with correct host + port)
GET / HTTP/1.0
[2x enter]

, , HTTP , . ... AJAX Javascript.

, ASP.Net . - Hangfire http://hangfire.io/. AJAX, .

0

. . - , ajax , .

0

All Articles