Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I monitor a folder for changes in the background of a Windows App?

I am writing a Windows 8 App that will primarily run in the background. This app will be specific to computers (i.e. no tablets or phones, in case that makes a difference). It needs to be able to watch a specified folder while it is running in the background and be notified when there is a change in that folder. Because it is a Windows Store App I cannot use a FileSystemWatcher, which would be perfect in my situation. Also, I cannot use a timer to watch the folder because these changes will be occurring every 10-15 seconds and the timer does not support times shorter than 15 minutes. What other options do I have?

like image 378
Garrett Avatar asked Dec 30 '12 20:12

Garrett


2 Answers

Since you can't use a timer that fires every 15 seconds or so, the only thing I can recommend is running a simple loop, which before the loop it checks the system time from the system clock, and then with each loop it checks difference between current system clock and the originally stored value. When you get to 15 seconds the loop stops and starts the code that checks the folder. If the code in the loop is simple and makes use of a Sleep call it shouldn't take hardly any system resources.

I hope this helps you!

like image 69
FrostyFire Avatar answered Oct 20 '22 11:10

FrostyFire


Have you looked at Windows Apps Background tasks? There's a question here: Windows 8 Live Tile Background Agent Using C#

like image 37
Andy Avatar answered Oct 20 '22 11:10

Andy