标题:怎么用取消键停止辅助线程???代码如下
只看楼主
wangcqing
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-3-16
 问题点数:0 回复次数:0 
怎么用取消键停止辅助线程???代码如下
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace VC2008programm
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }
      //  private Thread thread = new Thread(ThreadProc);
        private void button1_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(ThreadProc));
            thread.IsBackground = true;   
        
thread.Start();

           
this.button1.Enabled = false;

        
        }
        public  void ThreadProc()
        {
            for (int i = 0; i < 500; i++)
            {
                OutText(i.ToString());
                Thread.Sleep(100);
               
            }
        }
        public delegate void OutDelegate(string text);

        public void OutText(string text)
        {
            if (txt.InvokeRequired)
            {
                OutDelegate outdelegate = new OutDelegate(OutText);
                this.BeginInvoke(outdelegate, new object[] { text });
                return;
            }
            txt.Items.Add(text);
           // txt.AppendText("\t\n");
        }

        private void Form4_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
        停止辅助线程的语句怎么写?

        }


    }
}
搜索更多相关主题的帖子: 辅助 代码 线程 
2010-03-16 11:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-299571-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.111903 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved