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 Thr
c# 多线程传递参数以及任务
最新推荐文章于 2024-08-16 19:05:24 发布
这篇博客探讨了如何在C#中使用多线程并传递参数。通过示例代码展示了如何创建线程并启动,同时将`Student`对象作为参数传递给工作线程。此外,还介绍了使用`Task`类创建任务层次结构,包括父任务和子任务的执行流程。
摘要由CSDN通过智能技术生成