HttpResponse from background thread

J

jurot

Hi,
Can somebody help me,pls?

After the button-click on the web-page I execute another thread


private void btnExecutePlugin_Click(object sender,
System.EventArgs e)
{
MyThread pt = new MyThread( new MyFinalizeCallback(
MyCallbackFunction ) );
Thread t = new Thread( new ThreadStart( pt.ThreadProc
) );
t.Start();
}


..and now in MyCallbackFunction, which is called after the MyThred is
finished I want to send some response to the webpage. (e.g.
HttpContext.Current.Response("DONE!"))

I also tried to use it in IHttpAsyncHandler:

[code:1:75a49b527e]
public IAsyncResult BeginProcessRequest(HttpContext ctx,
AsyncCallback cb, object obj)
{
ctx.Response("HELLO WORLD!"); //THIS DIDN'T
WORK
ProcessRequestDelegate prg =
new ProcessRequestDelegate(ProcessRequest);
return prg.BeginInvoke(ctx, cb, obj);
}
[/code:1:75a49b527e]

..but it also didn't work.

Thanks in advance..

Jurot
 
S

Scott Allen

Because the page has finished executing and the context isn't useful
anymore.

I have an article on this issue here:
http://odetocode.com/Articles/112.aspx

Note that I would only recommend using background threads for Page
processing in very unique circumstances. In most cases I you are going
to limit your scalability taking this approach.

--
Scott
http://www.OdeToCode.com

Hi,
Can somebody help me,pls?

After the button-click on the web-page I execute another thread


private void btnExecutePlugin_Click(object sender,
System.EventArgs e)
{
MyThread pt = new MyThread( new MyFinalizeCallback(
MyCallbackFunction ) );
Thread t = new Thread( new ThreadStart( pt.ThreadProc
) );
t.Start();
}


.and now in MyCallbackFunction, which is called after the MyThred is
finished I want to send some response to the webpage. (e.g.
HttpContext.Current.Response("DONE!"))

I also tried to use it in IHttpAsyncHandler:

[code:1:75a49b527e]
public IAsyncResult BeginProcessRequest(HttpContext ctx,
AsyncCallback cb, object obj)
{
ctx.Response("HELLO WORLD!"); //THIS DIDN'T
WORK
ProcessRequestDelegate prg =
new ProcessRequestDelegate(ProcessRequest);
return prg.BeginInvoke(ctx, cb, obj);
}
[/code:1:75a49b527e]

.but it also didn't work.

Thanks in advance..

Jurot
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top