diff --git a/src/Tools/dotnet-watch/src/DotNetWatcher.cs b/src/Tools/dotnet-watch/src/DotNetWatcher.cs index 8431615c1e..38b457298b 100644 --- a/src/Tools/dotnet-watch/src/DotNetWatcher.cs +++ b/src/Tools/dotnet-watch/src/DotNetWatcher.cs @@ -93,10 +93,8 @@ namespace Microsoft.DotNet.Watcher if (finishedTask == processTask) { - _reporter.Warn("Waiting for a file to change before restarting dotnet..."); - // Now wait for a file to change before restarting process - await fileSetWatcher.GetChangedFileAsync(cancellationToken); + await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _reporter.Warn("Waiting for a file to change before restarting dotnet...")); } if (!string.IsNullOrEmpty(fileSetTask.Result)) diff --git a/src/Tools/dotnet-watch/src/Internal/FileSetWatcher.cs b/src/Tools/dotnet-watch/src/Internal/FileSetWatcher.cs index 3dc56cc452..55ad0e4b10 100644 --- a/src/Tools/dotnet-watch/src/Internal/FileSetWatcher.cs +++ b/src/Tools/dotnet-watch/src/Internal/FileSetWatcher.cs @@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Watcher.Internal _fileWatcher = new FileWatcher(reporter); } - public async Task GetChangedFileAsync(CancellationToken cancellationToken) + public async Task GetChangedFileAsync(CancellationToken cancellationToken, Action startedWatching) { foreach (var file in _fileSet) { @@ -41,12 +41,19 @@ namespace Microsoft.DotNet.Watcher.Internal }; _fileWatcher.OnFileChange += callback; + startedWatching(); var changedFile = await tcs.Task; _fileWatcher.OnFileChange -= callback; return changedFile; } + + public Task GetChangedFileAsync(CancellationToken cancellationToken) + { + return GetChangedFileAsync(cancellationToken, () => {}); + } + public void Dispose() { _fileWatcher.Dispose();