custom HttpHandler question

D

DalePres

I am trying to create a custom HttpHandler that will load a page but keep
the response object open while waiting for a message from a MessageQueue.
In the ProcessRequest method I call:

public void ProcessRequest(HttpContext context)
{
HttpResponse response = context.Response;
response.Buffer = false;
response.BufferOutput = false;
StringBuilder sb = new StringBuilder();
sb.Append("<HTML>\n<HEAD></HEAD>\n<BODY ");
sb.Append("bgcolor=\"black\" text=\"white\">\n");
response.Write(sb);
response.Flush();
response.Write("(" + DateTime.Now.ToString() + ") SignOn.");
response.Flush();

try
{
msgQ.ReceiveById(context.Session.SessionID, TimeSpan.FromSeconds(30));
}
catch (Exception ex)
{
response.Write("Error: " + ex.Message + "<BR>");
response.Flush();
}
sb = new StringBuilder();
sb.Append("</BODY>\n</HTML>\n");
response.Write(sb);
response.Flush();
}

After the handler receives the message from the MessageQueue, or the 30
second timeout occurs, the ProcessRequest method returns. What I am having
a problem with is that I want the portions of the page up to the sign on
message to be displayed while the process waits on the message from the
MessageQueue.

If I rem out the try/catch block shown above, the rest of the handler works
as expected.

Does anyone have any ideas how I might make this work?

Thanks in advance,

Dale
 
N

Natty Gur

Hi,

I try your code (loop instead of MQ) and it is working just fine.

SignOn displayed first and after 2-3 secound "Finish Process" displayed.

public void ProcessRequest(HttpContext context)
{
HttpResponse response = context.Response;
response.Buffer = false;
response.BufferOutput = false;
StringBuilder sb = new StringBuilder();
sb.Append("<html>\n<head></HEAD>\n<body ");
sb.Append("bgcolor=\"black\" text=\"white\">\n");
response.Write(sb);
response.Flush();
response.Write("(" + DateTime.Now.ToString() + ") SignOn.");
response.Flush();

try
{
string s = "";
for(long i=0;i < 10000;i ++)
{
s += i.ToString();
}
}
catch (Exception ex)
{
response.Write("Error: " + ex.Message + "<BR>");
response.Flush();
}
response.Write(" <BR> (" + DateTime.Now.ToString() + ") Finish
Process.");
response.Flush();

sb = new StringBuilder();
sb.Append("</body>\n</html>\n");
response.Write(sb);
response.Flush();
}


Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top