每个人。
我是这里和编程世界的新手。
MS docs所说的一项任务是可以保证完成的一项工作。我发现在发布版本中是正确的,但在调试版本中则不是。
我的测试代码非常简单。
static void Main(string[] args)
{
Console.WriteLine("1st Code executed");
Task task = new Task(() =>
{
Console.WriteLine("2nd Code executed");
Console.WriteLine("3rd Code executed");
});
task.Start();
Console.WriteLine("4th Code executed");
Console.ReadLine();
}
在调试模式下,它导致以下三个之一:
/*Mostly
* 1st Code executed
* 4th Code executed
* rarely
* 1st Code executed
* 4th Code executed
* 2nd Code executed
* rarely
* 1st Code executed
* 4th Code executed
* 2nd Code executed
* 3rd Code executed */
在发行版中,没有例外,尽管任务中的第4行和第4行按任意顺序排列,但在应用程序完成之前都显示了所有四行。
我的问题是,使应用程序完成而不以调试模式完成任务的原因是什么,此外,我如何通过调试选项来修复它(如果有的话。)>
每个。我是这里和编程世界的新手。 MS文档说任务是一项可以保证完成的工作。我发现在发布版本中确实如此,但在调试版本中却并非如此。我的...