How to make .NET 6.0 Hot Reload work on the simplest "Hello, World" console application?
Asked Answered
N

1

5

Consider this C# 10 / .NET 6.0 / Visual Studio 2022 "Hello, World" console application:

// See https://aka.ms/new-console-template for more information

foreach (int _ in Enumerable.Range(0, 100))
{
    Console.WriteLine("Hello, World!");
    Task.Delay(1000).Wait();
}

If I run this program with debugging, or without debugging, changing the World to Earth and then saving the file and clicking "Hot Reload" (Apply Code Changes) button does nothing. The program continues to write to console Hello, World!.

I can force the application to change the string without restarting without using Hot Reload, by using Edit and Continue instead, i.e. by making changes while the application is in break mode.

I did enable all the options for Hot Reload:

enter image description here

Why doesn't the Hot Reload work? Am I doing something wrong? This blog post states it should also work for Console apps.

Nursemaid answered 10/11, 2021 at 3:54 Comment(0)
B
6

If you change Task.Delay(1000).Wait() to await Task.Delay(1000) then hot reload on save will work. It seems when a thread is blocked, hot reload doesn't want to work.

Briefs answered 10/11, 2021 at 5:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.