美好的一天!
我尝试将每个3600次迭代的小例子编程并行,我创建了Task并启动它。
我应该停一下吗?
class Program
{
static void Main(string[] args)
{
int n=1000000;
List<Task> tasks = new List<Task>();
var sb = new StringBuilder();
for (int i = 0; i < n * 360; i++)
{
sb.Append("test");
if (i % 3600 == 0)
{
var task = Factory.GetTask(sb);
sb.Clear();
task.Start();
}
}
}
public static void WriteToFile(StringBuilder Sb)
{
// do work;
}
public sealed class Factory
{
private Factory()
{
}
public static Task GetTask(StringBuilder Sb)
{
return new Task(()=>Program.WriteToFile(Sb));
}
}