views:

759

answers:

3

Hi Everyone,

I'm using ASP.NET and C# and am exporting a very large results set to Excel. While my export code is running I would like to show a "loading" animated gif so the users will know their request is processing. I've been trying to do this with multithreading, but I am not very familiar with it. Can anyone guide me in the right direction? Thanks!

Jon

A: 

I've run into this same problem with generating reports. A simple solution would be to run the report at night and then write it to the server. Then provide a link to the report.

Brian Bolton
+1  A: 

Are you trying to do multi-threading on the server? What I'd recommend is in your client side javascript turn on a please wait message before posting to the server. Then on the client side when your done posting you turn the message off.

Without knowing more about your actual setup I can't help much further, but last time I implemented this I did something along these lines:

Assume we have a div called PrintLoadingPanel using JQUERY I set the div to display and take over the window:

    $("#printLoadingPanel")
       .css({display:"block",top:"0px",left:"0px",height:screen.availHeight});

I then will start a timer with a 1/2 second interval which will start checking if we are done printing. I'm only generating and downloading small PDF's so i needed a quicker response. If your report is really slow you might want to tweak this:

    window.setTimeout(checkIfDoneDownload,500);

Then my CheckIfDoneDownload function hits the server and checks if we finished generating the file and downloaded it. I am using JQUERY here again to call an AJAX enabled WCF service. You could substitute this with PageMethods or any other way to callback to the server.

function checkIfDoneDownload()
{

$.ajax({
  type: "POST",
  url: "../Services/Utilities.svc/IsPrintDownloadDone",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
  if (msg.d)
  {
    $("#printLoadingPanel").css("display","none");
  }
  else  {window.setTimeout(checkIfDoneDownload,500);}
  },  
  error: function (xhr, textStatus, errorThrown) {
  if (xhr.status==12030) {checkIfDoneDownload();}
}
});
}

Now on the server side, I am generating my downloads via an HTTP Handler. Essentially the first thing it does is set a session level flag to false, then the last thing it does is set it back to true. My check if done service just returns the value of the flag.

JoshBerke
Yeah, I was trying to use multi-threading on the server. I'll give your solution a try, thanks!
Jon
Yea do it on the client side...
JoshBerke
A: 

If you're in a position to use ASP.NET AJAX then I'd recommend using the UpdateProgress control (along with an UpdatePanel).

If you're after a nice animated gif image then check out Ajaxload.

Richard Ev
I tried this but the export to Excel failed because it requires a Response.Write()
Jon