How to display page while long-running process executing?

L

lmttag

Hello.
We're developing an ASP.NET 2.0 (C#) application and we're trying to
AJAX-enable it. We're having problem with a page not showing the page while
a long-running process is executing. So, we're looking for a way to display
the page with a "please wait..." message while the process is running, and
then, when the process is done, update the page with the actual results/page
content.

We have a page that opens another browser/page using JavaScript window.open,
and, in the second page's Page_Load, we call the long-running function. In
doing this, the browser and page do not completely render anything until the
long-running function is complete.

So, how can we make the page that calls the long-running process in
Page_Load display a page with some sort of please wait... message (and
probably an animated gif) while the function runs?

Is there something in the new ASP.NET AJAX stuff? Or, is there some other
way?

Thanks.
 
G

Guest

Create a layer (DIV) and make it visible. It says "please wait". At the end
of the render (bottom of HTML page), output JavaScript that hides the div.
That is the basic mechanics. I do not have a sample. :-(

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
S

Steven Cheng[MSFT]

Hello lmttag,

Regarding on such waring page for longrun task, in ASP.NET, we have the
following approachs so far:

1. Start the server-side long run task in a certain postback event, and
then in client-side page, use script (or html <meta> tag) to constantly
postback the page to check for the server-side task status(use session
variable ). If the task finished, stop those constantly postback script and
display final result.

2. During the time without ajax, we have the option to use some client-side
XMLHttp post component to send http request to server-side(to poll status
of the server-side long run task). This way, we can avoid constantly
refreshing the web page(as #1 does).

here are some web articles introduced some of such approaches:

#How To: Submit and Poll for Long-Running Tasks
http://msdn2.microsoft.com/en-us/library/ms979200.aspx

#Building a Better Wait Page
http://www.codeproject.com/aspnet/wait_page.asp

#Solve the Page Waiting Game with Threaded AJAX
http://www.devx.com/asp/Article/29617




3. Nowadays, we have the AJAX based pattern, it is somewhat like the #2,
but leverage existing ajax components. The microsoft AJAX framework just
provide such a well encapsulated AJAX framework that can help us build AJAX
web application. Here for long run task, you can start it in a certain
postback event, and then let the client-side call a AJAX webservice
function to constantly poll the status of the server-side task.

Here are reference about calling webservice in ASP.NET ajax application(and
the whole tutorial):


#Calling Web Services from Client Script in ASP.NET AJAX
http://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx

#ASP.NET AJAX Roadmap
http://ajax.asp.net/docs/default.aspx

Hope this helps. if you have any more specific questions, welcome to
discuss here also.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

lmttag

Steven,
Thank you for the information. It was very helpful.

I was able to get the 3rd option (ASP.NET AJAX) pattern working for a simple
situation. However, my situation is a bit more complex and I'm not sure how
to use the AJAX pattern and make it work. So, I was hoping that I could
give you some more info. and check to see if you could assist me.

As I mentioned in my original post, I have a page that opens another page
using the JavaScript window.open function. In the second page, I have no
controls, no buttons (no buttons to click to cause a postback), no div tags,
etc. What I'm doing in the second page is generating a SQL Server 2005
Reporting Services report, rendering it as PDF, and displaying the PDF in
the second page's browser.

For some reports, this generating/rendering of the report can take maybe 20
seconds. So, I need the page to display an animated gif with a message that
says "Please wait..." while, in the background, the report is being
generated. Then when the report is done being generated/rendered, I need
the animated gif and wait message to go away and have the PDF report
displayed.

I hope this makes sense. Would you be able to provide some suggestions/help
with this situation?

Here's some code snippets from my second page that is generating, rendering,
and displaying the report.

(Nothing in the markup for the page.)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Generated Report</title>
<link href="../CSS/ReportsStyleSheet.css" rel="Stylesheet"
type="text/css" />
</head>
<body>
<form id="formRenderReport" runat="server">
<div>
</div>
</form>
</body>
</html>

(The code-behind...)
public partial class Pages_RenderReport : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AddOnPreRenderCompleteAsync(new
BeginEventHandler(BeginAsyncOperation), new
EndEventHandler(EndAsyncOperation));
}
}

private System.IAsyncResult BeginAsyncOperation(object sender, EventArgs
e, AsyncCallback cb, object state)
{
// ...

// Connect to Reporting Services
ReportingExecution.ReportExecutionService rs = new
ReportingExecution.ReportExecutionService();
rs.Credentials =
System.Net.CredentialCache.DefaultCredentials;

// Local Reporting Services variables
byte[] result = null;
string format = "PDF";
string format = outputformat;
string historyID = null;
string devInfo = null;
string encoding;
string mimeType;
string extension;
ReportingExecution.Warning[] warnings = null;
string[] streamIDs = null;

// ...

try
{
// Set all the Reporting Services variables and
parameters and render the report
ReportingExecution.ExecutionInfo execInfo = new
ReportingExecution.ExecutionInfo();
ReportingExecution.ExecutionHeader execHeader = new
ReportingExecution.ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath1, historyID);
rs.SetExecutionParameters(parameters, "en-us");
System.String SessionId =
rs.ExecutionHeaderValue.ExecutionID;
result = rs.Render(format, devInfo, out extension, out
mimeType, out encoding, out warnings, out streamIDs);
execInfo = rs.GetExecutionInfo();

// Force the render out of the report to the browser
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AppendHeader("content-length",
result.Length.ToString());

switch (outputformat)
{
case "EXCEL":
Response.ContentType =
"application/vnd.ms-excel"; // Seems to work
break;
case "MHTML":
Response.ContentType = "message/rfc822";
break;
case "PDF":
Response.ContentType = "application/pdf";
break;
default:
Response.ContentType = "application/pdf";
break;
}

Response.BinaryWrite(result);
Response.Flush();
Response.Close();
Response.End();
}
catch (System.Exception ex)
{
// An exception occurred while trying to generate and
render the report
}


// Just needed to get a IAsyncResult to return
System.Net.WebRequest hwr =
System.Net.WebRequest.Create("http://localhost/");
return hwr.BeginGetResponse(cb, state);
}

private void EndAsyncOperation(System.IAsyncResult ar)
{
//
}
 
S

Steven Cheng[MSFT]

Hello lmttag,

Thanks for your reply.

From the page code you provided, you're currently using the asynchronous
page execution model. I think for your scenario, you do not need to use
this asynchronous executing model. Actually, you can consider using a
separate thread(manually created) to execute those code that access the
backend report server and generate the report output. Thus, your main page
can simply use synchronous page execution model(do not use async page), and
when it postback to start generating the report, it will create a new
thread to do the report generation and the page will return to client
immediately after start the new thread and display a label(show "report is
being generated......"), and the client page will use AJAX script to
constantly call a server-side webservice to check whether the report result
has been generated(by checking a session variable). If report has been
generated, it submit the page and the page render out the report content
(generated by the separate thread in the former stage). How do you think of
this?

If you still have any question or any further concern here, please feel
free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

lmttag

Hello again Steve,
Thank you so much for the information and suggestions. I'm going to look
into implementing your suggestions, although some other "fires" have come up
here that I'll need to take care of first. I'll probably be writing you
again for some more assistance, unless you have some code examples to get me
started.
Thanks again!
 
S

Steven Cheng[MSFT]

Thanks for your reply Imttag,

Nevermine, please feel free to take care of your most priority work and
followup here at your convenience. I can create a simple demo page (through
the ASP.NET AJAX framework) that shows how to display waiting message while
waiting for server-side long run processing. I'll posted code here later,
if you feel necessary, I can also emai the code to you.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

lmttag

Steven,
Hi. Thanks for all your help. I'm done with the other stuff I was working
on, so I'm now back to this showing progress issue.

I've been trying to do what you suggested in your previous post. However, I
guess I'm not that familiar with AJAX and threading yet because I can't get
it to work.

I'm having trouble creating a new thread and having the new thread able to
access the Response object (which I guess it can't). Also, I'm having
troubles because the Reporting Services render method returns a byte[] and
all the AJAX examples simply pass/return strings. My situation is a bit
more complex.

Anyway, I'd greatly appreciate any examples and/or demo code that could
possibly show me (or give me some tips) on how to accomplish my task.

Thanks again.
 
S

Steven Cheng[MSFT]

Hi Imgtag,

I have just created a very simple test page through ASP.NET AJAX
application framework. It contains a page which postback and start a
background thread to process a longrun task. The page will return
immediately and use client script to constantly ping the server-side for
task status and postback again if the task is finished. Would you shot me
a mail so that I can send you the project via email? You can get me
through the email in my signature (remove "online")

If there is anything unclear, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

lmttag

Hi Steven,
I sent you an e-mail yesterday so that you would have my e-mail address to
send me your example project. But, I just wanted to follow up on this post
also. If you don't get my e-mail, let me know and I can re-send it.
Thanks.
 
S

Steven Cheng[MSFT]

Hi Imttag,

I have received your email and replied you with the test project/page in
the attachment. Please let me know if you get the reply and if you have any
further questions or anything we can help, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Imttag,

Just a continue followup to see how are you doing on this issue? Does the
test sample provide you some idea on this? If there is anything else we can
help, please don't hesitate to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Tammy Phan

Hi Steve,
just wonder if you can post the code online. I have 1st page with a lot
of stuff. When I click a button on that page, it redirects to the 2nd
page. I need a "wait ..." on the 2nd page. The 2nd page has 2 buttons
and a gridview ( take 10 sec to show up). So I just wonder any simple
solution to display the message "wait..." for user to wait for the 2nd
page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top