小编Joh*_*lin的帖子

C#任务未完成(命令提示符中没有结果)

using System;
using System.Threading.Tasks;

namespace _1._8_Starting_A_New_Task
{
    public static class Program
    {
        public static void Main()
        {
            Task t = new Task(() =>
            {
                for (int x = 0; x < 100; x++)
                {
                    Console.Write('*');
                }
            });

            t.Wait();
        }

    }
}
Run Code Online (Sandbox Code Playgroud)
  • 此应用程序编译并运行显示空白屏幕(等待任务完成)
  • 任务保持等待状态
  • 没有输出显示/写入控制台
  • 为什么不?
  • 应用程序永久保持"等待"状态
  • 为什么?
  • 代码目标:启动新任务,等待任务完成,退出应用程序

c# console task wait task-parallel-library

0
推荐指数
1
解决办法
869
查看次数

标签 统计

c# ×1

console ×1

task ×1

task-parallel-library ×1

wait ×1