主程序通过Thread类创建异步线程
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace _20211013启动线程方法2Thread类
{
class Program
{
static void Main(string[] args)
{
Thread t1 = new Thread(Func01);
t1.Start(122);
MyClass myclass = new MyClass(122);
Thread t2 = new Thread(myclass.Func01);
t2.Start();
Console.ReadKey();
}
static void Func01(object i)
{
int i2 = (int)i;
Console.WriteLine("t1开始下载:"+i2);
i2++;
Thread.Sleep(2000);
Console.WriteLine("t1下载完成:"+i2);
Object i3 = i2;
}
}
}
自建类 提供对象方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace _20211013启动线程方法2Thread类
{
class MyClass
{
int i;
public MyClass(int i1)
{
this.i = i1;
}
public void Func01()
{
int i2 = i;
Console.WriteLine("t2开始下载:" + i2);
i2++;
Thread.Sleep(2000);
Console.WriteLine("t2下载完成:" + i2);
}
}
}