HttpResponse from background thread

Discussion in 'ASP .Net' started by jurot, Jul 14, 2004.

  1. jurot

    jurot Guest

    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
    jurot, Jul 14, 2004
    #1
    1. Advertising

  2. jurot

    Scott Allen Guest

    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

    On 14 Jul 2004 05:08:01 -0500, -spam.invalid
    (jurot) wrote:

    >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


    --
    Scott
    http://www.OdeToCode.com
    Scott Allen, Jul 14, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Hanson
    Replies:
    4
    Views:
    8,520
    Yan-Hong Huang[MSFT]
    Aug 1, 2003
  2. Matthew Trunnell

    HttpResponse.ValidateFileRange()

    Matthew Trunnell, Feb 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    423
    Matthew Trunnell
    Feb 6, 2004
  3. =?Utf-8?B?QWxleCBLbGltYW50b3Y=?=

    HttpResponse Headers

    =?Utf-8?B?QWxleCBLbGltYW50b3Y=?=, Apr 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    845
    =?Utf-8?B?QWxleCBLbGltYW50b3Y=?=
    Apr 2, 2004
  4. =?Utf-8?B?Sm9zZSBGbG9yZXM=?=

    RE: How to read content of httpResponse.OutputStream

    =?Utf-8?B?Sm9zZSBGbG9yZXM=?=, May 12, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    18,658
    =?Utf-8?B?Sm9zZSBGbG9yZXM=?=
    May 18, 2004
  5. =?Utf-8?B?Sm9oYW5uYQ==?=
    Replies:
    3
    Views:
    1,939
    =?Utf-8?B?Sm9oYW5uYQ==?=
    Oct 15, 2004
Loading...

Share This Page