I created a Windows-based application to monitor the file changes from network-shared folders using .NET FileSystemWatcher. The Application is running on AWS EC2 ts.large Windows Server 2016 Datacenter, 8 GB RAM.
The application works well when monitoring 500 network shared folders, but it constantly raises the exception as below when monitoring 1000 network shared folders.
System.ComponentModel.Win32Exception (0x80004005): Insufficient system resources exist to complete the requested service
In Windows Task Manager, it shows high CPU usage up to 70 - 90% even no any file change in the folders, the RAM looks normal, around 120 MB.
Additionally, if I use the application to monitor 1000 local folder. It works well without any issue.
I guess it might be related to how Windows manages the memory (non-paged memory). But I am not sure exactly how to fix this issue. Very appreciate your suggestion!