线程的使用

来源:互联网 发布:dota2网络连接不上 编辑:程序博客网 时间:2024/04/30 21:53
把你的工作方法放在一个单独的方法里,然后:1. 用Threading.Thread类:System.Threading.Thread th = new Thread(new ThreadStart(this.DoWirk));th.Start();2. ThreadPool:System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(this.DoWork), null)第两个参数是传给线程用的参数。2. 用backgroupworker控件. 功能多一些。private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e){ BackgroundWorker worker = sender as BackgroundWorker; e.Result = this.DoWork();}
0 0