I need to fire an event when certain file is created. But this file is created in Temp folder inside a directory that is created with it. So I will have to set up monitoring of whole Temp dir with all subdirectories and I'm concerned about performance impact.
I know exact name and path of file and need to only track its creation. Is it better to poll File.Exists once a second or set up a FileSystemWatcher? Maybe there is a way to disable monitoring of all events except file creation and maybe it will be faster than polling?
I can't really test it because usage pattern of Temp directory is quite unpredictable.
I dont get it. Why you have to set "watch" the whole temp dir? And not just the folder where that file is?
I know exact name and path of file
BIT OF GOOGLE: Use FileSystemWatcher on a single file in C#
This is going to have probably better performance than polling every x ammount of time.
But still, i have read and even happened to me, FSW is not 100% reliable.
So i would think of two approaches:
1) Do a mix of FSW, Poll and user intervention (ie, refresh button)
2) Get some fine drugs and read this: System Minifilter Driver
https://msdn.microsoft.com/en-us/library/windows/hardware/ff540402%28v=vs.85%29.aspx
EDIT: new link: https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/filter-manager-concepts And a nice code sample: https://github.com/microsoft/Windows-driver-samples/tree/master/filesys/miniFilter/change
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With