标签:
//动态多线程
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static int I = 10000;
static int J = 10;//要多少个线程
static int H = 0;
static string[] aList=new string[10];
static void Main(string[] args)
{
MyStart();
}
static void MyStart()
{
Thread thr = new Thread(new ThreadStart(StartH));
thr.Start();
}
static void StartH()
{
H++;
int a = H;
if (H<J)
{
MyStart();
}
string info = "";
for (int i = (a-1)*(I/J)+1; i <= a*(I/J); i++)
{
info += i + "\r\n";
}
aList[a - 1] = info;
if (a==J)
{
Thread.Sleep(500);
File.WriteAllLines("C:\\a.log", aList);
}
}
}
}
标签:
原文地址:http://www.cnblogs.com/milest/p/4289595.html