开发者

Advice on background processing in .net

开发者 https://www.devze.com 2023-01-18 10:30 出处:网络
I have a webpage that reads data from an external source.It can take awhile to retrieve the data. I was wondering if someone could give me an idea on the best way to have this happen in the backgroun

I have a webpage that reads data from an external source. It can take awhile to retrieve the data.

I was wondering if someone could give me an idea on the best way to have this happen in the background. I would like the page to come up and display 'Processing' (or somthing like that) in the panel where the data will eventually be displayed.

I thought of the BackgroundWorker component, or maybe an AsyncPostBackTrigger... not sure if these will even solve the pro开发者_开发问答blem to my satisfaction.

So... does anyone have any ideas as to a good approach to the problem?

Thanks for the advice!!


I think what you're looking for is Ajax. You want to make the request from the client side in a way that will allow the user to continue viewing other content until that loads.

.NET has a number of different techniques for support AJAX requests - ranging from UpdatePanel controls to Async Operations. Which technique you use depends on the details of exactly what you're trying to do.

You could also just use a library like jQuery to make async requests for content to a separate page or service in your web application.


I would use AJAX, send the page to the user with a processing message, then request the external source from a XmlHttpRequest using JavaScript (through your site as a proxy).


Well, one solution is to stick an asp:Timer on your page inside an update panel*. Have the OnTick event retrieve the current status of the processing (progress percentage, if it's done, what it's doing, etc.). There are various ways the the processing part can notify the page of its progress; just giving it a progress property and updating it as it runs is one way to do it. Note that the OnTick event will NOT be doing the processing; it is just to figure out the status of the processing.

*If you put it outside the update panel, it will tick every Interval instead of every Timer.Interval + TimeToReloadUpdatePanel, which will be a big problem if TimeToReloadUpdatePanel >= Timer.Interval.


My thinking is that web queries should be fast so I would look for ways to improve the query performance. If the data is going to be the same for each query, I would try caching it. If that is not feasible, I would use jQuery to make an async request and display a loading image until the query finishes.

0

精彩评论

暂无评论...
验证码 换一张
取 消