mythread.start();
后面加上
mythread.join();

解决方案 »

  1.   

    源代码:就是一个抓取淘宝下拉框词的程序:    private void taobao_old_key(List<string> tmp)
            {
                foreach (string keyword in tmp)
                {
                    //此处代码较长,以dosomthing代替,主要是获取源码的过程,没有使用到任何控件
                    dosomthing;
                    //下面的是使用正则表达式匹配源码,找到数据,添加到listbox控件当中
                    Regex taobaoold_regex = new Regex(@"\[""(?<taobaoold>.*?)"".*?""");
                    MatchCollection taobaoold_match = taobaoold_regex.Matches(mystringbuilder.ToString());
                    List<string> matches = new List<string>();
                    for (int i = 0; i < 10 && i < taobaoold_match.Count; i++)
                    {
                       matches.Add(taobaoold_match[i].Groups[1].Value);
                    }
                    AddToListBox(DroplistBox, matches);
                }
            }
            private void AddToListBox(ListBox listbox, string match)
            {
                if (listbox.InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(() =>
                    {
                        AddToListBox(listbox, match);
                    }));
                }
                else
                {
                    listbox.Items.Add(match);
                }
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                CheckForIllegalCrossThreadCalls = false;
            }
            private void Startbutton_Click(object sender, EventArgs e)
            {
                List<string> listString;
                //对liststring赋值操作不写了,直接略过,然后将liststring的值传递到函数中去,就是挖掘liststring中关键词的数据
                Start = new Thread(() =>
                            {
                                taobao_old_key(listString);
                             });
                Start.IsBackground = true;
                Start.Start();
                Start.Join();
                MessageBox.Show("查询完毕!");       
            }就是这样的一段代码,点击按钮之后,软件直接停住了,什么数据都不显示,去掉join()k就可以继续搜索了
      

  2.   

    源代码:就是一个抓取淘宝下拉框词的程序:    private void taobao_old_key(List<string> tmp)
            {
                foreach (string keyword in tmp)
                {
                    //此处代码较长,以dosomthing代替,主要是获取源码的过程,没有使用到任何控件
                    dosomthing;
                    //下面的是使用正则表达式匹配源码,找到数据,添加到listbox控件当中
                    Regex taobaoold_regex = new Regex(@"\[""(?<taobaoold>.*?)"".*?""");
                    MatchCollection taobaoold_match = taobaoold_regex.Matches(mystringbuilder.ToString());
                    List<string> matches = new List<string>();
                    for (int i = 0; i < 10 && i < taobaoold_match.Count; i++)
                    {
                       matches.Add(taobaoold_match[i].Groups[1].Value);
                    }
                    AddToListBox(DroplistBox, matches);
                }
            }
            private void AddToListBox(ListBox listbox, List<string> matches)
            {
                if (listbox.InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(() =>
                    {
                        AddToListBox(listbox, match);
                    }));
                }
                else
                {
                    foreach (string match in matches)
                    {
                        listbox.Items.Add(match);
                    }
                }
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                CheckForIllegalCrossThreadCalls = false;
            }
            private void Startbutton_Click(object sender, EventArgs e)
            {
                List<string> listString;
                //对liststring赋值操作不写了,直接略过,然后将liststring的值传递到函数中去,就是挖掘liststring中关键词的数据
                Start = new Thread(() =>
                            {
                                taobao_old_key(listString);
                             });
                Start.IsBackground = true;
                Start.Start();
                Start.Join();
                MessageBox.Show("查询完毕!");       
            }就是这样的一段代码,点击按钮之后,软件直接停住了,什么数据都不显示,去掉join()k就可以继续搜索了
    下面的这个是正确的代码,上面的代码有些问题!
      

  3.   

    源代码:就是一个抓取淘宝下拉框词的程序:    private void taobao_old_key(List<string> tmp)
            {
                foreach (string keyword in tmp)
                {
                    //此处代码较长,以dosomthing代替,主要是获取源码的过程,没有使用到任何控件
                    dosomthing;
                    //下面的是使用正则表达式匹配源码,找到数据,添加到listbox控件当中
                    Regex taobaoold_regex = new Regex(@"\[""(?<taobaoold>.*?)"".*?""");
                    MatchCollection taobaoold_match = taobaoold_regex.Matches(mystringbuilder.ToString());
                    List<string> matches = new List<string>();
                    for (int i = 0; i < 10 && i < taobaoold_match.Count; i++)
                    {
                       matches.Add(taobaoold_match[i].Groups[1].Value);
                    }
                    AddToListBox(DroplistBox, matches);
                }
            }
            private void AddToListBox(ListBox listbox, List<string> matches)
            {
                if (listbox.InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(() =>
                    {
                        AddToListBox(listbox, match);
                    }));
                }
                else
                {
                    foreach (string match in matches)
                    {
                        listbox.Items.Add(match);
                    }
                }
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                CheckForIllegalCrossThreadCalls = false;
            }
            private void Startbutton_Click(object sender, EventArgs e)
            {
                List<string> listString;
                //对liststring赋值操作不写了,直接略过,然后将liststring的值传递到函数中去,就是挖掘liststring中关键词的数据
                Start = new Thread(() =>
                            {
                                taobao_old_key(listString);
                             });
                Start.IsBackground = true;
                Start.Start();
                Start.Join();
                MessageBox.Show("查询完毕!");       
            }就是这样的一段代码,点击按钮之后,软件直接停住了,什么数据都不显示,去掉join()k就可以继续搜索了
    下面的这个是正确的代码,上面的代码有些问题!求高手指点为何会卡主
      

  4.   

    lz你不看msdn吗,join 就是block的。它等待线程结束才会继续执行。Thread.Join Method
    Blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping.http://msdn.microsoft.com/en-us/library/95hbf2ta(v=vs.110).aspx
      

  5.   

    lz可以看看这里的例程BackgroundWorker Class
    http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
      

  6.   

    主要是我不知道我遇到的问题叫什么,不知道如何在MSDN搜索呀!
      

  7.   

    http://www.albahari.com/threading/
      

  8.   

    Join会阻塞在taobao_old_key线程中,而taobao_old_key线程又想通过委托回到UI线程更新,这样肯定会出现界面假死啦。最简单的改法是将MessageBox.Show("查询完毕!");移到下面位置:    private void taobao_old_key(List<string> tmp)
            {
                foreach (string keyword in tmp)
                {
                    //此处代码较长,以dosomthing代替,主要是获取源码的过程,没有使用到任何控件
                    dosomthing;
                    //下面的是使用正则表达式匹配源码,找到数据,添加到listbox控件当中
                    Regex taobaoold_regex = new Regex(@"\[""(?<taobaoold>.*?)"".*?""");
                    MatchCollection taobaoold_match = taobaoold_regex.Matches(mystringbuilder.ToString());
                    List<string> matches = new List<string>();
                    for (int i = 0; i < 10 && i < taobaoold_match.Count; i++)
                    {
                       matches.Add(taobaoold_match[i].Groups[1].Value);
                    }
                    AddToListBox(DroplistBox, matches);
                }
                MessageBox.Show("查询完毕!");
            }
      

  9.   

    http://www.cnblogs.com/mashang/archive/2009/08/01/1536730.html
    BeginInvoke 和 Invoke 的区别
      

  10.   

    对了,修改的时候记得注释掉Join。
      

  11.   

            private void Startbutton_Click(object sender, EventArgs e)
            {
                List<string> listString;
                //对liststring赋值操作不写了,直接略过,然后将liststring的值传递到函数中去,就是挖掘liststring中关键词的数据
                Start = new Thread(() =>
                            {
                                taobao_old_key(listString);
                                MessageBox.Show("查询完毕!");
                            });
                Start.IsBackground = true;
                Start.Start();
            }