日期:2014-05-17  浏览次数:21013 次

为什么按钮click事件结束后,才能点击别的按钮?
我有两个按钮:发送SendButton 和 停止发送StopButton
他们的单击事件大体如下
//发送事件
SendButton_Click() 
{
     //事件处理
}
//停止发送事件
StopBulltton_Click()
{

}

我发现当点击发送按钮后,发送按钮一直处于按下状态,停止按钮也不能点击,知道发送事件处理完毕后,按钮才起来,停止按钮也可以点击了。请问,如何做到在发送过程中停止啊?

------解决方案--------------------
这个你就要看一下多线程方面的了。。
------解决方案--------------------
这是因为UI线程的阻塞,如果不想在处理事件时(比较长时间的逻辑事件)让UI线程阻塞,可以让你的发送事件和停止事件分别放到线程中去处理(可以用委托实现)。更多的资料,可以搜索界面假死关键字,有大把资料。
------解决方案--------------------

        private Thread thread;
        private void SendButton_Click(object sender, EventArgs e)
        {
            thread = new Thread(SendData);
            thread.Start();
        }

        private void StopBulltton_Click(object sender, EventArgs e)
        {
            if (thread != null && thread.IsAlive)
            {
                thread.Abort();
            }
        }

        /// <summary>
        /// 发送数据
        /// </summary>
        private void SendData()
        {
        }