int taskcount = 15;//限制线程总数为15
TaskFactory fac = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(taskcount));

List movielist = domovie.GetNoJsonMovieList();
int i = 0;
foreach (movie tutu in movielist)
{
fac.StartNew(s => {
SetMovieJson(tutu.Guid);
Log(++i + ” / ” + DateTime.Now.ToString() + ” / ” + Thread.CurrentThread.ManagedThreadId + ” 正在生成 ” + tutu.Guid + ” / ” + tutu.Title);
}

    

发表评论