using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication6
{
public class MyThread
{
private string data;
public MyThread(string data)
{
this.data = data;
}
public void ThreadMain()
{
Console.WriteLine("Running in a thread,data: {0}",data);
}
}
class Program
{
static void Main(string[] args)
{
MyThread obj = new MyThread("Info");
Thread t3 = new Thread(obj.ThreadMain);
t3.Start();
}
}
}
本文介绍如何使用C#语言创建一个自定义的线程类,并通过线程池来启动线程实例,实现多线程的运行。通过实例演示了如何在主线程中创建线程对象,调用其线程方法,并观察多线程执行的效果。
5万+

被折叠的 条评论
为什么被折叠?



