Hello @Atal Sarker ,
They changed the way file enumeration works. Instead of letting Windows do the filtering for you, .NET now retrieves all file names and applies the search pattern in managed code.
A few things you can try:
Use Directory.EnumerateFiles() instead of GetFiles()
EnumerateFiles streams results instead of loading them all at once, so it starts returning files sooner and avoids some overhead.
Enumerate once and filter in your code
If you call GetFiles() many times with different patterns, that is costly now because .NET applies the pattern in managed code. A better approach is to enumerate all files once and apply your own filtering logic.
Example:
foreach (var path in Directory.EnumerateFiles(sharePath, "*"))
{
if (MatchesMyCriteria(path)) { /* process */ }
}
Tune EnumerationOptions
You can increase BufferSize (try 16 KB or 64 KB) to reduce round trips over SMB. Also check AttributesToSkip and IgnoreInaccessible if needed:
var options = new EnumerationOptions
{
BufferSize = 16 * 1024,
IgnoreInaccessible = true
};
foreach (var path in Directory.EnumerateFiles(sharePath, "*", options))
{
// process
}
Avoid creating FileInfo unless necessary
Stick to strings for paths unless you really need metadata.
Check environment factors
- SMB signing is now required by default on Windows 11/Server 2025, which can slow down directory listings on older NAS devices. If you’re in a trusted network, testing with signing disabled can confirm if that’s the bottleneck.
- Antivirus scanning on the share can also add latency. Try excluding the path temporarily to see if it helps.
- Make sure the share uses SMB2 or SMB3, not SMB1.
I hope this helps.