110,536
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
test();
Console.WriteLine(".......按任意键退出");
Console.ReadKey();
}
static async void test()
{
while (true)
{
Console.WriteLine(DateTime.Now.ToString("H:mm:ss.fff"));
await Task.Delay(1000);
}
}
}
}
以后,我不会再在这里纠结什么“线程”的说法,因为我觉得各种语言各种平台都在强调 Task 时代已经很普遍了,再满口是过时的线程概念会出很大的问题的。
int 秒 = DateTime.Now.Second;
do
{
if (DateTime.Now.Second != 秒)
{
//要执行的代码
break;
}
Application.DoEvents();
} while (true);
int x = System.Environment.TickCount;
while (System.Environment.TickCount - x < 1000)
{
}