How to get a string from a thread onto a page?

Discussion in 'ASP .Net' started by charles, Feb 23, 2006.

  1. charles

    charles Guest

    Hi:

    I created a thread in Page_Load and get a string through a socket from
    another process. Then I show this string in a textbox on the page. When
    Page_Load exits, the string does not display on the textbox.

    If I add a Response.Flush() statement, I get an exception of type:
    {System.Web.HttpException}.

    What went wrong with my approach? Please help. Thank you in advance!

    Charles
    2/23
     
    charles, Feb 23, 2006
    #1
    1. Advertising

  2. charles

    Bruce Barker Guest

    you proably did not add code in prerender or onload to wait for the the
    thread to complete. thus by the time the thread complete, the request is
    done, and the browser has already rendered the page.

    -- bruce (sqlwork.com)

    "charles" <> wrote in message
    news:...
    > Hi:
    >
    > I created a thread in Page_Load and get a string through a socket from
    > another process. Then I show this string in a textbox on the page. When
    > Page_Load exits, the string does not display on the textbox.
    >
    > If I add a Response.Flush() statement, I get an exception of type:
    > {System.Web.HttpException}.
    >
    > What went wrong with my approach? Please help. Thank you in advance!
    >
    > Charles
    > 2/23
    >
     
    Bruce Barker, Feb 23, 2006
    #2
    1. Advertising

  3. charles

    charles Guest

    Thank you, Bruce, for your promptive response!

    Would you please tell me how to write in onload to wait for the thread
    to complete?

    I have 2 lines in Page_Load to start a thread:

    readThread = new Thread( new ThreadStart( RunServer ) );
    readThread.Start();

    Thanks!

    Charles
    2/23
     
    charles, Feb 23, 2006
    #3
  4. You could try to join() your thread to the existing thread actioning your
    web request. This should pause your on_load method until the thread
    concludes. Be warned though, your delaying the web server from responding
    efficiently.

    http://msdn.microsoft.com/library/d...frlrfsystemthreadingthreadclassjointopic1.asp

    If your making a socket call, make sure you get a timeout invoked if the
    call fails so the joined thread can return, otherwise your in trouble if the
    thread fails to terminate. Thats one of the problems with sub-threading
    events in asp.net.

    You might want to consider instead making a webservice call within the load
    method to invoke the socket and pass your value back, and make use of its
    timeout ability to allow your load method to continue cleanly.

    http://msdn.microsoft.com/library/d...otocolswebclientprotocolclasstimeouttopic.asp
    -- Regards
    John Timney
    Microsoft MVP

    "charles" <> wrote in message
    news:...
    > Thank you, Bruce, for your promptive response!
    >
    > Would you please tell me how to write in onload to wait for the thread
    > to complete?
    >
    > I have 2 lines in Page_Load to start a thread:
    >
    > readThread = new Thread( new ThreadStart( RunServer ) );
    > readThread.Start();
    >
    > Thanks!
    >
    > Charles
    > 2/23
    >
     
    John Timney \( MVP \), Feb 23, 2006
    #4
  5. charles

    charles Guest

    Dear John:

    Thank you for your valuable advice. I did try the thread Join()
    approach. Then I found that I could not end my thread. The situation
    is: I am implementing an event that will fire when the data from
    another process arrives. And I need to continuously receive and display
    the data in a web form until that process quits. If I end the thread in
    order to display the data, I need to re-create a thread, re-connect the
    socket and wait for data (and probably already missed the data). In a
    Windows form I never needed to do that, since there are many ways to
    display the arrived data such as using Winsock.

    I have not tried using Web Service yet. Do you think that I will end up
    with the same problem as using thread? Or could you give me some
    totally different suggestion? Thanks again!

    Charles
    2/27
     
    charles, Feb 27, 2006
    #5
    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. Geoff Cox

    how to get trackbar onto a web page?

    Geoff Cox, Aug 24, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,724
    Geoff Cox
    Aug 29, 2005
  2. Geoff Cox

    get a slider onto a web page?

    Geoff Cox, Aug 25, 2005, in forum: Java
    Replies:
    27
    Views:
    845
    Geoff Cox
    Aug 30, 2005
  3. Geoff Coope
    Replies:
    4
    Views:
    598
    Geoff Coope
    Mar 8, 2006
  4. Guyon Morée

    How does one get onto planet.python.org?

    Guyon Morée, Jan 31, 2008, in forum: Python
    Replies:
    0
    Views:
    253
    Guyon Morée
    Jan 31, 2008
  5. Replies:
    9
    Views:
    703
    Steve Holden
    Apr 6, 2008
Loading...

Share This Page