日期:2014-05-18 浏览次数:20916 次
using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace ParameterizedThreadStartCS { class Program { static void Main(string[] args) { Thread newThread; ParameterizedThreadStart PTS1 = new ParameterizedThreadStart(PrintName); newThread = new Thread(PTS1); newThread.Name = "Thread 1"; newThread.Start(10); ParameterizedThreadStart PTS2 = new ParameterizedThreadStart(PrintNum); newThread = new Thread(PTS2); newThread.Name = "Thread 2"; newThread.Start(10); Console.ReadLine(); } static void PrintName(object times) { for (int i = 1; i < (int)times +1; i++) { Console.WriteLine("*****我叫某某某*****\n"); Thread.Sleep(3000); } } static void PrintNum(object times) { for (int i = 1; i < (int)times + 1; i++) { Console.WriteLine("*****我的学号是0001*****\n"); Thread.Sleep(3000); } } } }
using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace ParameterizedThreadStartCS { class Program { static void Main(string[] args) { Thread newThread; ParameterizedThreadStart PTS = new ParameterizedThreadStart(Print); for(int i=1;i<3;i++) { console.WriteLine("Thread "+i); newThread = new Thread(PTS); newThread.Name=i.ToString(); newThread.Start(10); } Console.ReadLine(); } static void Print(object times) { for (int i = 1; i < (int)times +1; i++) { Console.WriteLine("*****我叫某某某,我的学号是0001*****\n"); Thread.Sleep(1); } } } }