Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for file change when process exits #47427

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/BuiltInTools/dotnet-watch/EnvironmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class Names
public static bool IsPollingEnabled => ReadBool("DOTNET_USE_POLLING_FILE_WATCHER");
public static bool SuppressEmojis => ReadBool("DOTNET_WATCH_SUPPRESS_EMOJIS");
public static bool RestartOnRudeEdit => ReadBool("DOTNET_WATCH_RESTART_ON_RUDE_EDIT");
public static TimeSpan ProcessCleanupTimeout => ReadTimeSpan("DOTNET_WATCH_PROCESS_CLEANUP_TIMEOUT_MS");
public static TimeSpan ProcessCleanupTimeout => ReadTimeSpan("DOTNET_WATCH_PROCESS_CLEANUP_TIMEOUT_MS", defaultValue: TimeSpan.FromSeconds(5));

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

private static TimeSpan ReadTimeSpan(string variableName)
=> Environment.GetEnvironmentVariable(variableName) is var value && long.TryParse(value, out var intValue) && intValue >= 0 ? TimeSpan.FromMilliseconds(intValue) : TimeSpan.FromSeconds(5);
private static TimeSpan ReadTimeSpan(string variableName, TimeSpan defaultValue)
=> Environment.GetEnvironmentVariable(variableName) is var value && long.TryParse(value, out var intValue) && intValue >= 0 ? TimeSpan.FromMilliseconds(intValue) : defaultValue;
}
6 changes: 5 additions & 1 deletion src/BuiltInTools/dotnet-watch/HotReloadDotNetWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using Microsoft.Build.Graph;
using Microsoft.CodeAnalysis;
using Microsoft.DotNet.Cli.Utils;

namespace Microsoft.DotNet.Watch
{
Expand Down Expand Up @@ -218,8 +219,11 @@ void FileChangedCallback(ChangedPath change)
}
catch (OperationCanceledException)
{
// Ctrl+C, forced restart, or process exited.
Debug.Assert(iterationCancellationToken.IsCancellationRequested);
waitForFileChangeBeforeRestarting = false;

// Will wait for a file change if process exited.
waitForFileChangeBeforeRestarting = true;
break;
}

Expand Down
Loading