Web page load for asynchronous call

I have a simple webpage in ASP.NET/C#. Currently, for a complete view of the data, I need to call a block of code that runs on background threads and can take several minutes. I got this to the point (using the async attribute in the page declaration) to execute and return the fine using html after it is completed. What I would like to do is let me return immediately with the “boot page” and then refresh this page when the background work is complete. Right now I'm not getting anything on the page while processing background work. Any ideas on a better way or smart way to do this would be greatly appreciated!

Thanks,

Zig

+4
source share
3 answers

I agree with the comments posted above.

I would, however, implement the “processor” as a separate page using ashx (handler), since they are really easy to call and poll from javascript, and you simply encode the process request event stream into the response stream.

I would like to show you an example on my site, but my host decided to spend a week from my site while they update .net on their servers (you can imagine that they did not particularly like it).

In fact, although in my case I have a page that uses data from: Bbc Google Amazon Amazon YouTube some other random sites.

The page will be returned to the user and individual controls on the page, then make ajax callbacks to the server for your parts.

The default content for tags into which feedback data will be loaded is a simple animated gif image that looks the same as a flash or silverlight boot circle.

As soon as the data is returned, the gif is replaced with the content uploaded by the server.

This means that the client sees “loading”, and the server is busy processing everything (seemingly synchronously from his point of view) that the client needs.

This is a clean user interface and the code is really simple.

I tried out the idea when I looked at how to download files using silverlight.

The basic concept:

  • ajax call "ashx". (maybe 10 javascript lines)
  • the server is processing the request. (depends on the complexity of the request, variables passed through the request)
  • the answer fills 1 element on another page. (ajax cllback does this)

Hope this helps :)

+1
source

There are many ways to implement what you describe using Ajax , but if you want to keep it really simple, you can just Flush() your answer with some loading screen before you run long-running tasks:

 <div> Loading.. <% Response.Flush(); %> <% System.Threading.Thread.Sleep(5000); %> Done! </div> 
0
source

What you want is called HTTP Server Push or HTTP streaming or long polling. Depending on how this is done.

There are many examples on the Internet, as well as articles that address issues in detail. I will start by exploring these issues.

You can also check this SO question on an HTTP stream ...

Cross-browser implementation of "HTTP Streaming" (push) AJAX

There is a link to an excellent article.

Or this long poll example

How to implement the basic "long survey"?

or

fooobar.com/questions/tagged / ...

Hope this helps.

0
source

Source: https://habr.com/ru/post/1309709/


All Articles