Skip to content

Commit ae300dd

Browse files
authored
Wait for file change when process exits (#47427)
1 parent 4dc9d20 commit ae300dd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/BuiltInTools/dotnet-watch/EnvironmentVariables.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static class Names
2828
public static bool IsPollingEnabled => ReadBool("DOTNET_USE_POLLING_FILE_WATCHER");
2929
public static bool SuppressEmojis => ReadBool("DOTNET_WATCH_SUPPRESS_EMOJIS");
3030
public static bool RestartOnRudeEdit => ReadBool("DOTNET_WATCH_RESTART_ON_RUDE_EDIT");
31-
public static TimeSpan ProcessCleanupTimeout => ReadTimeSpan("DOTNET_WATCH_PROCESS_CLEANUP_TIMEOUT_MS");
31+
public static TimeSpan ProcessCleanupTimeout => ReadTimeSpan("DOTNET_WATCH_PROCESS_CLEANUP_TIMEOUT_MS", defaultValue: TimeSpan.FromSeconds(5));
3232

3333
public static string SdkRootDirectory =>
3434
#if DEBUG
@@ -51,6 +51,6 @@ public static class Names
5151
private static bool ReadBool(string variableName)
5252
=> Environment.GetEnvironmentVariable(variableName) is var value && (value == "1" || bool.TryParse(value, out var boolValue) && boolValue);
5353

54-
private static TimeSpan ReadTimeSpan(string variableName)
55-
=> Environment.GetEnvironmentVariable(variableName) is var value && long.TryParse(value, out var intValue) && intValue >= 0 ? TimeSpan.FromMilliseconds(intValue) : TimeSpan.FromSeconds(5);
54+
private static TimeSpan ReadTimeSpan(string variableName, TimeSpan defaultValue)
55+
=> Environment.GetEnvironmentVariable(variableName) is var value && long.TryParse(value, out var intValue) && intValue >= 0 ? TimeSpan.FromMilliseconds(intValue) : defaultValue;
5656
}

src/BuiltInTools/dotnet-watch/HotReloadDotNetWatcher.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using Microsoft.Build.Graph;
77
using Microsoft.CodeAnalysis;
8+
using Microsoft.DotNet.Cli.Utils;
89

910
namespace Microsoft.DotNet.Watch
1011
{
@@ -218,8 +219,11 @@ void FileChangedCallback(ChangedPath change)
218219
}
219220
catch (OperationCanceledException)
220221
{
222+
// Ctrl+C, forced restart, or process exited.
221223
Debug.Assert(iterationCancellationToken.IsCancellationRequested);
222-
waitForFileChangeBeforeRestarting = false;
224+
225+
// Will wait for a file change if process exited.
226+
waitForFileChangeBeforeRestarting = true;
223227
break;
224228
}
225229

0 commit comments

Comments
 (0)