using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleSample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("这是主线程");
DateTime dtStart = DateTime.Now;
for (int i = 0; i < 100; i++)
{
Student s = new Student();
s.name = "张三" + i;
s.sex = "男";
s.age = 28;
Thread t = new Thread(ThreadWithParas);
t.Start(s); //要给线程传递数据,需某个存储数据的类或结构
}
DateTime dtEnd = DateTime.Now;
TimeSpan span = (TimeSpan)(dtEnd - dtStart);
Console.ReadLine();
Console.WriteLine("运行的时间 " + span.Milliseconds);
Console.ReadLine();
}
static void ThreadWithParas(object o)
{
Student s = o as Student;
Console.
c# 多线程传递参数以及任务
最新推荐文章于 2024-05-22 15:16:09 发布