Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to get a string from a thread onto a page?

Reply
Thread Tools

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

 
 
charles
Guest
Posts: n/a
 
      02-23-2006
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

 
Reply With Quote
 
 
 
 
Bruce Barker
Guest
Posts: n/a
 
      02-23-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
Reply With Quote
 
 
 
 
charles
Guest
Posts: n/a
 
      02-23-2006
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

 
Reply With Quote
 
John Timney \( MVP \)
Guest
Posts: n/a
 
      02-23-2006
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/de...jointopic1.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/de...meouttopic.asp
-- Regards
John Timney
Microsoft MVP

"charles" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
Reply With Quote
 
charles
Guest
Posts: n/a
 
      02-27-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tkinter, add pressed buttons onto string display string, how to? skanemupp@yahoo.se Python 9 04-06-2008 02:24 AM
get a slider onto a web page? Geoff Cox Java 27 08-30-2005 07:13 AM
how to get trackbar onto a web page? Geoff Cox ASP .Net 2 08-29-2005 08:18 AM
Photo quality - onto paper or onto CD? Theseeker Digital Photography 8 10-04-2004 08:59 PM
Putting a string onto a stream to be read into a DataGrid James Norton-Jones ASP .Net 8 08-01-2003 12:15 PM



Advertisments