C# 多线程启动和管理
C# 多线程启动和管理
1.直接启动线程执行
//4.0写法 { }) { IsBackground = true }.Start();
//net 4.5 的语句 //System.Threading.Tasks.Task.Run(() => //{ //});
List<Task> taskList = new List<Task>();
TaskFactory taskFactory = new TaskFactory();
taskList.Add(taskFactory.StartNew(() => //
}));
//等待所有线程结束
Task.WaitAll(taskList.ToArray());
- Thread无参
Thread thread = new Thread(new ThreadStart(PlayMusic)); thread.Start();
4.Thread有参
Thread thread = new Thread(new ParameterizedThreadStart(setSecond)); thread.Start(new Object() { });
跨线程修改
txty.Invoke((MethodInvoker)delegate txty.Text = "";
});