多线程小实例:
创建一个子线程去完成程序的运行工作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Studythread2
{
class Program
{
static void Main(string[] args)
{
//创建一个线程
Thread thread = new Thread(new ThreadA().Test);
//使线程处于就绪状态,没有执行
thread.Start();
}
}
public class ThreadA
{
//子线程,担任程序运行工作
public void Test()
{
for (int i = 0; i < 100;i++ )
{
var a = i%2;
if (a == 1)
{
Console.WriteLine(i);
}
}
}
}
}
浙公网安备 33010602011771号