码迷,mamicode.com
首页 > 编程语言 > 详细

多线程

时间:2015-02-13 09:12:41      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

//动态多线程
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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!