如何保留一个带有睡眠的按钮单击动作与另一个不带睡眠的按钮单击动作 [英] how to retain a button clicks action with a sleep against another button click action without sleep

查看:72
本文介绍了如何保留一个带有睡眠的按钮单击动作与另一个不带睡眠的按钮单击动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..
我的问题是在asp.net的两个不同的更新面板中有两个标签和两个按钮.
更新面板包含两个按钮.
单击按钮时..,它将更新相应的标签文本.
问题是,假设我在我的button1_click()方法中延迟了5秒,当我立即单击button1和button2时,label2被更新了..,而label1没有被更新.

你能建议我错了吗?

这是后端代码-

Hi..,
My problem is i have two labels and two buttons in two different update panel in asp.net.
The update panels contains two buttons.
when buttons are clicked.., it will update the corresponding label text.
The issue is, suppose i gave a delay of 5 seconds in my button1_click() method, when i click button1 and button2 immediately, label2 is gettin updated.., whereas label1 is not getting updated.

can u suggest me wher im goin wrong??

this is back-end code-

protected void Button1_Click2(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(5000);
            Label1.Text = "Hello";
        }
        protected void Button2_Click1(object sender, EventArgs e)
        {
            Label2.Text = "World";
        }

推荐答案

除非您不愿意搞砸,否则您无法入睡,进入等待状态甚至在UI线程上调用任何冗长的操作.您应该将另一个线程用于此类目的.

我不知道5秒钟后更新标签的目的.您也可以使用计时器,但是最建议使用线程.这取决于您还要做什么.

—SA
You cannot sleep, put to wait state and even call any lengthy operation on your UI thread unless you want to screw up things. You should use another thread for purposes like that.

The purpose of updating a label after 5 seconds is unknown to me. You can use timer as well, but thread is the most recommended. It depends what else are your going to do.

—SA


这篇关于如何保留一个带有睡眠的按钮单击动作与另一个不带睡眠的按钮单击动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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