473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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

Feb 23 '06 #1
4 837
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" <ch**********@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr 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

Feb 23 '06 #2
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

Feb 23 '06 #3
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" <ch**********@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr 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

Feb 23 '06 #4
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

Feb 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Harald Armin Massa | last post by:
I need to do some synchronisations like in a cron.job import time from threading import Thread class updater(Thread): def run(self): while True: do_updates() time.sleep(600)
44
by: Charles Law | last post by:
Hi guys. I'm back on the threading gig again. It's the age-old question about waiting for something to happen without wasting time doing it. Take two threads: the main thread and a worker...
3
by: Andrew Baker | last post by:
OK this has me perplexed, puzzled and bamboozled! I have a remoting service which I displayed a message box in. I then wondered what would happen if a client made a call to the service while the...
8
by: Jason Chu | last post by:
I have a webpage which uploads a big file onto access db. if the file is say around 30 megs, it'll take around a minute for it to get put into the access db. I didn't want the user to wait for it,...
3
by: fiefie.niles | last post by:
I am using a thread. Inside the thread there is a sub ThreadMain. I am calling the thread from the main program MainForm. Inside the thread, if I am calling a sub (say doProcess) from the...
7
by: Sin Jeong-hun | last post by:
I've using thread a lot in C#, but all of them were just single method with no return value or paramenters. It may sound bizarre but, can't it be a class? I'm writing an Windows application that...
6
by: HolyShea | last post by:
All, Not sure if this is possible or not - I've created a class which performs an asynchronous operation and provides notification when the operation is complete. I'd like the notification to be...
8
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of...
9
by: Pubs | last post by:
Hi all, I want to call a function with some intial parameters with in a thread. At the end of the function execution it should return a value to the caller. Caller is outside the thread. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.