using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleTest
{
class Program
{
static void Main(string[] args)
{
Account acc1 = new Account("Thread One", 1);
Thread t1 = new Thread(new ThreadStart(acc1.Running));
t1.Start();
Account acc2 = new Account("第二进程", 3);
Thread t2 = new Thread(new ThreadStart(acc2.Running));
t2.Start();
Console.ReadKey();
}
}
public class Account
{
int count;
string threadName;
internal Account(string name, int times)
{
this.count = times;
this.threadName = name;
}
internal void Running()
{
while (count < 10)
{
Thread.Sleep(1000 * count);
Console.WriteLine("进程名称:" + this.threadName + ",正在计数:" + count);
count++;
}
}
}
}
C#简单的多线程实例
最新推荐文章于 2024-08-15 19:01:20 发布