开发者

How do I close a splash message after generating a file?

I've run into a rather sticky situation and I was hoping you all could help. As part of my application, I'm generating a file for my users. Unfortunately, the time it takes to generate this file could be close to 5 minutes. In order to appease my users, I'm showing a message asking them to please wait. Once I have the file generated, I want to return the file to them and clear the message. I'm using the ASP.NET timer to check when the file has finished generating.

My problem comes once the file has finished generating. At the point, I need to do three things:

  1. Pass the file to the user.
  2. Close the message.
  3. Disable the Timer.

My problem comes from the fact that once I've finished writing the file to the response, my postback doesn't finish,开发者_JAVA百科 so the Viewstate doesn't get updated, so the message and Timer are still there.

Any ideas?


I think you need to break this down into several stages instead of doing all your processing in a single page request. If I were designing this I'd look to do something like this..

  1. User initiates creation of file by clicking some link on your site. This writes some info to a DB table, or otherwise kicks off a process that generates the file.
  2. User is presented with a "please wait" page that can update itself every N seconds.
  3. When file is generated the DB table is updated with the status of "ready".
  4. The "please wait" page refreshes, the job is seen to be complete, the file is now downloaded.

Assuming the "please wait" page uses some identification based upon an authenticated user then this has the benefit of allowing the user to collect their file regardless of whether they get bored and/or accidentally close their browser.

In fact, why not check out these SO posts which cover similar ground...

Handling Long Running Reports Long-running code within asp.net process BackgroundWorker thread in ASP.NET

... and there are others (search for "ASP.NET long running")


I've done similar things but without using the timer. Basically I launch a dialog box OnClientClick and then let the server side to it's thing (OnClick). I use the following javascript to handle the postback returning in the OnClientClick:

Dialog.show();    
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(
                    function(sender, args) {                            
                        MyDialog.hide();
                    }); 


The KISS method is redirecting to a loading page (with loading message etc.) which in turn calls the slow loading resource. The page churns away showing the loading message until the resource is ready. The only downside is that if your resource really does take 5 minutes to generate, the request will time out. If this is the case, @Martin-Peck has a better solution already posted.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜