NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 28 29 30 31 32 … 93 Next »
FileSystemEvent triggers twice

 
  • 0 Vote(s) - 0 Average
FileSystemEvent triggers twice
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,603
Threads: 389
Joined: Dec 2004
#1
2008-11-06, 10:36 PM
I want to automatically reload the user settings file when a user makes a change to prevent them having to restart the dvbt radio service. Code as follows...
Code:
private static DvbtrUserSettings UserSettings;
private FileSystemWatcher UserSettingsFileWatcher;
Code:
UserSettings = new DvbtrUserSettings(GBInstallDir + @"plugins\DVB-T Radio\DVBTRadio.xml");

UserSettingsFileWatcher = new FileSystemWatcher(GBInstallDir + @"plugins\DVB-T Radio", "DVBTRadio.xml");
UserSettingsFileWatcher.NotifyFilter = NotifyFilters.LastWrite;
UserSettingsFileWatcher.Changed += new FileSystemEventHandler(UserSettingsFileWatcher_Changed);
UserSettingsFileWatcher.EnableRaisingEvents = true;
Code:
void UserSettingsFileWatcher_Changed(object sender, FileSystemEventArgs e)
{
    Log.WriteLine("FileWatcher_Changed event received: " + e.FullPath);
    if (e.ChangeType == WatcherChangeTypes.Changed)
    {
        Log.WriteLine("UserSettings file change. Reloading...");
        UserSettings.Load();
        Log.WriteLine("UserSettings: ");
        // Cut for brevity
    }
}
Log file entries...
Code:
06/11/2008 22:14:00.452 FileWatcher_Changed event received: C:\Program Files\Devnz\GBPVR\plugins\DVB-T Radio\DVBTRadio.xml
06/11/2008 22:14:00.452 UserSettings file change. Reloading...
06/11/2008 22:14:00.467 UserSettings:
06/11/2008 22:14:00.467     AudioDecoderName:
06/11/2008 22:14:00.467     DisableScreenSaver: False
06/11/2008 22:14:00.467     EnableGetNowNext: True
06/11/2008 22:14:00.467     ONID: -1
06/11/2008 22:14:00.467     PlaybackBufferDelay: 500
06/11/2008 22:14:00.467     ScanFullEPG: True
06/11/2008 22:14:00.467     StopOnChannelChange: False
06/11/2008 22:14:00.467     UseLivePlayback: True
06/11/2008 22:14:00.467 FileWatcher_Changed event received: C:\Program Files\Devnz\GBPVR\plugins\DVB-T Radio\DVBTRadio.xml
06/11/2008 22:14:00.467 UserSettings file change. Reloading...
06/11/2008 22:14:00.483 UserSettings:
06/11/2008 22:14:00.483     AudioDecoderName:
06/11/2008 22:14:00.483     DisableScreenSaver: False
06/11/2008 22:14:00.483     EnableGetNowNext: True
06/11/2008 22:14:00.483     ONID: -1
06/11/2008 22:14:00.483     PlaybackBufferDelay: 500
06/11/2008 22:14:00.483     ScanFullEPG: True
06/11/2008 22:14:00.483     StopOnChannelChange: False
06/11/2008 22:14:00.483     UseLivePlayback: True
At first I thought it might be receiving an event for the folder AND one for the file which is why I got it to log e.FullPath but it's two events just for the file. I'm simply opening the file in Notepad (before starting the service) then making a change and saving without closing.

Any ideas?

Cheers,
Brian
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#2
2008-11-06, 11:01 PM
Do you use the IEventNotification and the ImenuTask?

I think both of these run so you may want a static initialised variable and test that before starting the filesystemwatcher.

If false, start your filesystemwatcher and then set your initialised to true.
JavaWiz
Offline

Posting Freak

Jacksonville, FL. USA
Posts: 2,522
Threads: 141
Joined: Dec 2006
#3
2008-11-06, 11:02 PM
from microsoft:

Quote:Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several OnChanged and some OnCreated and OnDeleted events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by FileSystemWatcher.
maybe you'll have to track last update time, and set some threshold to ignore if it has changed within the last 5 seconds or something...
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,603
Threads: 389
Joined: Dec 2004
#4
2008-11-07, 01:41 AM
Thanks guys - no end of experimenting could give me a real answer to why it is happening. I tried disabling my AV software but that didn't change anything.

I can understand a 'move' operation involves create, copy and delete steps and how that would generate multiple events but simply editing one xml node's inner text from 'true' to 'false' and saving without closing Notepad???

Oh well - I've always found file system monitoring a bit odd.

As you suggested JavaWiz, the only way I can prevent it is keeping a DateTime token of last call to the eventhandler - if it was less than 1 second ago, it just drops out. The processing is taking a few 10's of milliseconds so I think that should cover it.

Cheers,
Brian
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode