ChrisW
ChrisW

Reputation: 56113

Background task in ASP.NET

I am writing a web application using ASP.NET (not MVC), with .NET v4 (not v4.5).

I fetch some of the data which I must display from a 3rd-party web service, one of whose methods takes a long time (several seconds) to complete. The information to be fetched/prefetched varies depending on the users' initial requests (because different users ask for details about different objects).

In a single-user desktop application, I might:

To do something similar using ASP.NET, I guessed I can:

Do you foresee problems, can you suggest improvements?

[There are other questions on StackOverflow about ASP.NET and background tasks, but these all seem to be about fetching and updating global application data, not session-specific data.]

Upvotes: 1

Views: 495

Answers (1)

Avi Turner
Avi Turner

Reputation: 10456

Why not use same discipline as in a desktop application:

  1. Load the page without the data from the service ( = Display my UI as quickly as possible)
  2. Fetch the service data using an ajax call (= Have a non-UI background task to fetch the information in advance)
  3. this is actually the same, although you can show an animated gif indicating you are still in progress... (Therefore hope have an already-fetched/cached version of the data, by the time the user drills down into the UI to request it)

In order to post an example code it will be helpful to know if you are using jquery? plain javascript? something else? no javascript?

Edit
I am not sure if this was your plan but Another idea is to fetch the data on server side as well, and cache the data for future requests.
In this case the stages will be:

  1. Get a request.
  2. is the service data cached?
    2.a. yes? post page with full data.
    2.b. no? post page without service data.
    2.b.i. On server side fetch service data and cache it for future requests.
    2.b.ii. On client side fetch service data and cache it for current session.

Edit 2:
Bare in mind that the down side of this discipline is that in case the method you fetch the data changes, you will have to remember to modify it both on server and client side.

Upvotes: 1

Related Questions