Skip to content
This repository was archived by the owner on Nov 6, 2018. It is now read-only.
Closed
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
23 changes: 21 additions & 2 deletions src/FS.Physical/PhysicalFilesWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,27 @@ private void TryEnableFileSystemWatcher()
if ((!_filePathTokenLookup.IsEmpty || !_wildcardTokenLookup.IsEmpty) &&
!_fileWatcher.EnableRaisingEvents)
{
// Perf: Turn off the file monitoring if no files to monitor.
_fileWatcher.EnableRaisingEvents = true;
// Don't capture the current ExecutionContext and its AsyncLocals onto the events causing them to live forever
var restoreFlow = false;
try
{
if (!ExecutionContext.IsFlowSuppressed())
{
ExecutionContext.SuppressFlow();
restoreFlow = true;
}

// Perf: Turn off the file monitoring if no files to monitor.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is terrible

_fileWatcher.EnableRaisingEvents = true;
}
finally
{
// Restore the current ExecutionContext
if (restoreFlow)
{
ExecutionContext.RestoreFlow();
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/FS.Physical.Tests/PhysicalFileProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Testing.xunit;
Expand Down