Skip to content
Merged
Changes from 3 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
7 changes: 6 additions & 1 deletion src/MSBuild.UnitTests/MSBuildServer_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,13 @@ public void BuildsWhileBuildIsRunningOnServer()
_env.WithTransientProcess(pidOfServerProcess);

string? dir = Path.GetDirectoryName(markerFile.Path);
using var watcher = new System.IO.FileSystemWatcher(dir!);
// mre must be declared before watcher so that it is disposed after watcher.
// With `using var`, disposal happens in reverse declaration order, so watcher
// is disposed first (stopping event delivery) before mre is disposed. Reversing
// this order would allow late FileSystemWatcher callbacks to call mre.Set() on
// a disposed ManualResetEvent, causing an ObjectDisposedException.
Comment thread
rainersigwald marked this conversation as resolved.
Outdated
using ManualResetEvent mre = new ManualResetEvent(false);
using var watcher = new System.IO.FileSystemWatcher(dir!);
Comment thread
rainersigwald marked this conversation as resolved.
watcher.Created += (o, e) =>
{
_output.WriteLine($"The marker file {markerFile.Path} was created. The build task has been started.");
Expand Down