当前位置:编程学习 > C#/ASP.NET >>

初学者小问题,关于线程的,大家帮忙看看

在click事件里,进了线程,出线程就直接结束了,thread.start()后面的代码就不执行了,而且也没报错,这是为什么,大家有没有遇到过这种情况?
手机发贴不大舒服,代码没放上来,大家帮忙看看,谢谢了。 --------------------编程问答-------------------- 帮楼主顶一下,还没用过线程,期待大神们给个资料 --------------------编程问答-------------------- 没代码真不知道你在说什么? --------------------编程问答-------------------- 。。。上代码好吗? --------------------编程问答-------------------- public text()
        {
            
            InitializeComponent();
            dFun1 = new dFun(SetValue);
        }

        //线程
        delegate void dFun(int v);
        dFun dFun1;
        private Thread thread;

        private void button1_Click(object sender, EventArgs e)
        {
            PublicData.pubvar.linesin.AddRange(richTextBox1.Lines);
            richTextBox1.Clear();
            thread = new Thread(new ThreadStart(fun));
            thread.Start();//有问题,直接过了
            for (int i = 0; i < PublicData.pubvar.linesout.Count; i++)
            {
                richTextBox1.AppendText(PublicData.pubvar.linesout[i] + "\r\n");
            }
         }
        public void fun()
        {
                PublicData.pubvar.v = 10;
                progressBar1.Invoke(dFun1, PublicData.pubvar.v);
                ToList tl = new ToList();
                Translate tr = new Translate();
                Display dp = new Display();
                tl.tolist();
                PublicData.pubvar.v = 20;
                progressBar1.Invoke(dFun1, PublicData.pubvar.v);
                if (NetTest.IsConnectedToInternet())
                {
                    tr.internettranslate();
                }
                else
                {
                    tr.localtranslate();
                }
                dp.display();
                //PublicData.pubvar.v = 90;
                progressBar1.Invoke(dFun1, PublicData.pubvar.v);
                thread.Abort();
        }
        private void SetValue(int v)//int v
        {
            progressBar1.Value = PublicData.pubvar.v;
        } --------------------编程问答-------------------- public text()
        {
            
            InitializeComponent();
            dFun1 = new dFun(SetValue);
        }

        //线程
        delegate void dFun(int v);
        dFun dFun1;
        private Thread thread;

        private void button1_Click(object sender, EventArgs e)
        {
            PublicData.pubvar.linesin.AddRange(richTextBox1.Lines);
            richTextBox1.Clear();
            thread = new Thread(new ThreadStart(fun));
            thread.Start();//有问题,直接过了
            for (int i = 0; i < PublicData.pubvar.linesout.Count; i++)
            {
                richTextBox1.AppendText(PublicData.pubvar.linesout[i] + "\r\n");
            }
         }
        public void fun()
        {
                PublicData.pubvar.v = 10;
                progressBar1.Invoke(dFun1, PublicData.pubvar.v);
                ToList tl = new ToList();
                Translate tr = new Translate();
                Display dp = new Display();
                tl.tolist();
                PublicData.pubvar.v = 20;
                progressBar1.Invoke(dFun1, PublicData.pubvar.v);
                if (NetTest.IsConnectedToInternet())
                {
                    tr.internettranslate();
                }
                else
                {
                    tr.localtranslate();
                }
                dp.display();
                //PublicData.pubvar.v = 90;
                progressBar1.Invoke(dFun1, PublicData.pubvar.v);
                thread.Abort();
        }
        private void SetValue(int v)//int v
        {
            progressBar1.Value = PublicData.pubvar.v;
        } --------------------编程问答-------------------- 代码贴出来了,大家帮忙看看,手一抖,发了2次
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,