asp.net使用多线程更新UI
发布时间:2020-08-16 05:38:04 所属栏目:asp.Net 来源:互联网
导读:我有一个包含以下内容的ASP.NET网站 asp:UpdatePanel ID=UpdatePanel1 runat=server ContentTemplate asp:Label ID=Label1 runat=server Text=Label/asp:Label /Content
我有一个包含以下内容的ASP.NET网站 <asp:UpdatePanel ID="UpdatePanel1" runat="server" > <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> 我创建了一个线程函数.在执行此功能期间,我想更新用户界面上的一些控件. protected void Page_Load(object sender,EventArgs e) { new Thread(new ThreadStart(Serialize_Click)).Start(); } protected void Serialize_Click() { for (int i = 1; i < 10; i++) { Label1.Text = Convert.ToString(i); UpdatePanel1.Update(); System.Threading.Thread.Sleep(1000); } } 如何在线程执行期间更新Web控件?我是否需要强制“UpdatePanel1”进行回发?怎么样? 解决方法您需要使用客户端计时器(或其他方法)让浏览器向服务器请求更新,例如以下简化示例:<asp:UpdatePanel ID="up" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="timer_Ticked" /> <asp:Label ID="Label1" runat="server" Text="1" /> </ContentTemplate> </asp:UpdatePanel> 然后在你的代码隐藏中: protected void timer_Ticked(object sender,EventArgs e) { Label1.Text = (int.Parse(Label1.Text) + 1).ToString(); } 如果您的后台进程正在更新某个状态,则您需要将共享状态存储在会话,http缓存或数据库中.请注意,由于许多因素,缓存可能会过期,如果IIS回收应用程序池,后台线程可能会被杀死. (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 属性似乎根本不起作用
- Asp.net配合easyui实现返回json数据实例
- asp.net – 以纯文本识别URL
- asp.net – Visual Studio 2010图表控件:使Y轴成为整数值,
- asp.net-mvc – 在MVC Razor视图中使用@RenderBody有什么意
- asp.net-mvc – CKEditor图像上传
- asp.net-mvc-3 – 使用@ Html.Raw有风险吗?
- asp.net-mvc – ASP.NET MVC Beta 1:DefaultModelBinder错
- asp.net-mvc – 使用Razor视图引擎 – 如何格式化十进制值以
- asp.net-mvc-3 – MVC 3 $.ajax – 响应似乎是从部分视图缓
推荐文章
站长推荐
- asp.net – 什么是system.globalization它和本地
- asp.net – 在fileupload中选择立即调用C#函数文
- asp.net-mvc-4 – MVC 4 DropDownListFor错误 –
- asp.net – 如何从复选框列表中获取最新的选定值
- webservice的两种调用方式
- asp.net-mvc – System.Web.Mvc.WebViewPage.Mod
- asp.net – 如何正确过滤数据表(datatable.selec
- asp.net – Orchard CMS是否支持移动呈现?
- ASP.NET中的基页
- asp.net – 如何使用javascript生成假回发?
热点阅读