标签文本未从新线程更新 [英] Label Text Not Updating from new Thread

查看:80
本文介绍了标签文本未从新线程更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#Web应用程序,当单击一个按钮时,它会启动一个新线程来进行一些处理.
我在Label控件中显示一条用户消息,指示该过程已开始.我将来自标签控件的引用传递给起始线程对象.线程完成后,我希望线程更新标签文本"以指示处理已完成.问题是标签文本未更新.我在主屏幕上使用UpdatePanel.当我指示线程正在启​​动但在线程结束时未更新时,它的工作正常.有任何想法吗?

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?

推荐答案

尝试一下-
如果只有一台Web服务器,则创建一个静态状态对象-最好是一个Dictionary,将线程ID作为键,将状态作为值.
一旦线程创建,运行或完成-维护此Dictionary对象中的状态.
创建线程后,将线程ID或Dictionary对象键发送到前端并将其存储在隐藏变量中.
在前端启动一个JavaScript计时器,并使用静态页面方法检查此状态并更新状态标签.
确保在线程完成后删除状态对象.
如果您具有Web场,则状态对象将不起作用,因此请将其移动到状态表中.更新表并从表中读取.
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.


这篇关于标签文本未从新线程更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆