OK, let's start off with a screenshot of the finished Widget:
While browsing the list of Widgets through Widget Forge, I stumbled upon Bobs LaunchList.
Bobs LaunchList is a simple launcher that allows you to launch files from a specific folder. You can filter any number of document types (i.e., .exe, .doc, .txt), limit the number of files displayed, display a custom icon for the folder, and more.
Well, people often share files through network shares on LANs, and I had heard a friend mention that he would like to monitor the contents of a directory on a network share without having to visit the directory at periodic intervals of time. Well, one of the solutions could be to point Bobs LaunchList to the directory of interest on the networks share and modify the Widget to refresh the list of files displayed in it at fixed intervals of time that can be configured by the user.
What I did
I introduced a settings node in BobsLaunchList.config file called dirListReloadTime:
<name>Directory Listing Reload Time</name>
<description>Sets the delay between automatic reloads of the directory
listing (Default: 10 minutes).</description>
The default-value of this element is set by the following in the config file:
BobsLaunchList encapsulates all directory listing code in a method called "Init". All the settings of the Widget are also obtained in Init. So I introduced the following additional code there:
reloadTime = 60 * 1000
Here I basically get the value of "reloadTime" attribute from the config file and convert it to milliseconds.
I initialize the timer with the value of reloadTime when the Widget is activated.
Next, I introduced a handler for the timer.
At each tick of the timer, Init() gets the value of "reloadTime" element from the settings of the Widget, stores it in the variable named reloadTime, and redraws the file listing of the directory being monitored. Before terminating this event handler I set the timer to tick again reloadTime milliseconds later.
Additionaly, I deleted the timer in the Widget_Deactivate method.
// delete timers
Thanks to Robert Lausevic who wrote the original Bobs LaunchList Widget.