Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a C# web application which starts a new thread to do some processing when a button is Clicked.
I display a user message in a Label control indicating that the process has started. I pass a reference from the lable control to the starting thread object. When the thread is finished I want the thread to update the label Text to indicate that the processing is complete. The problem is the label text is not updating. I'm using UpdatePanel on the main screen. Its working fine when I indicate that the thread is starting but is not updating when the thread is finished. Any ideas?
Posted
Updated 1-Feb-12 10:46am
v2
Comments
Sergey Alexandrovich Kryukov 1-Feb-12 16:50pm    
Clearly, there is an idea? How can you imagine that? You need to send an HTTP response to the HTTP request, and where it's done? In a separate thread? How? Maybe you can send some code sample? This can be non-trivial, as everything is driven by client side requests.
--SA
Kethu Sasikanth 1-Feb-12 20:38pm    
May be the HTTP Response is complete, done its job, before thread(update label one) is finished?
Member 7969139 1-Feb-12 21:45pm    
Thats exactly right. The button click event just launches the new thread then returns. The new thread runs for about 5 minutes then returns. I want to notifiy the main thread that the process has ended. Its almost like I need another postback. But how would I do that?
ZurdoDev 2-Feb-12 9:02am    
Your thread is running on the server so you have to ping for when it is done. The server cannot push stuff to the client by creating the connection. Your connection is already done. Sounds like you really need to use a jQuery .Ajax() call instead to kick off this second process that way you started it on the client and the client will receive it when it is done. http://api.jquery.com/jQuery.ajax/

1 solution

Try this -
If you have a single web server, create a static status object - a Dictionary is best, with the thread id as key and status as value.
As soon as the thread is created, running or completed - maintain the status in this Dictionary object.
When the thread is created, send the thread id or the Dictionary object key to the front end and store it in a hidden variable.
In the front end kick off a javascript timer and check this status using a static page method and update the status label.
Make sure that you delete the status object after the thread has completed.
If you are having a web farm, the status object will not work, so move this to a status table. Update the table and read from the table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900