using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace CheckMortonCode.Tests
{
class TestTask
{
private static object printLockObj = new object();
private static int num = 0;
private static int top = 0;
private static void RunOneTask()
{
Thread.Sleep(1000);
}
public static void PrintProgress(int i, int cnt)
{
lock (printLockObj)
{
num++;
top = Console.CursorTop;
Console.WriteLine($"{num} / {cnt}: {i}");
Console.SetCursorPosition(0, top);
}
}
public static void RunAllTask()
{
var sw = new Stopwatch();
sw.Start();
Parallel.For(0, 100, i =>
{
RunOneTask();
PrintProgress(i, 100);
}
);
sw.Stop();
var second = sw.ElapsedMilliseconds / 1000;
Console.WriteLine($"\n用时:{second}s");
Console.ReadLine();
}
}
}