本文介绍了当我点击btnstop事件时,deletethread必须停止该过程。有人可以帮忙吗?感谢adavance的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击btnstop事件时,它不会停止DeleteThread的工作过程。



我尝试了什么:

when I am click on btnstop event it doesn't stop the DeleteThread working process.

What I have tried:

this is another btnDelete event.

ivate void btnDelete_Click(object sender, EventArgs e)
        {
            Thread DeleteThread = new Thread(deleteThread);
                DeleteThread.Start();
            if(btnDelete.Enabled==false)
            {
                DeleteThread.Abort();
            }
        }



deleteThread函数


function for deleteThread

blic void deleteThread()
        {
            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("delete from demo where id='" + item.Cells[0].Value.ToString() + "'", con);
                Thread.Sleep(1000);
                cmd.ExecuteNonQuery();
                MessageBox.Show("your selected " + item.Cells[0].Value.ToString() + " record is deleted");
                con.Close();
            }
        }



这是btnstop事件


this is the btnstop event

private void btnStop_Click(object sender, EventArgs e)
        {
            btnDelete.Enabled = false;
        }

推荐答案


这篇关于当我点击btnstop事件时,deletethread必须停止该过程。有人可以帮忙吗?感谢adavance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 02:17