C#中关于线程的问题!
我的一段代码如下,简写一下:
Thread mythread;
mythread=new Thread(new wajue())
mythread.start();
messagebox.show("程序执行完毕");
我想做的就是wajue()采用线程的方式执行完毕之后,能够弹出对话框,但是我实际过程中,启动线程之后就开始弹对话框了,程序还没有执行完毕,请问高手门如何执行完wajue()之后弹出对话框!
[解决办法]
wajue里面你写了什么?
[解决办法]
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("查询完毕!");
????????}
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();
}