OnIdle

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

OnIdle

Post by trixmoto » Sun Jan 03, 2010 5:34 pm

Has anyone used the OnIdle event before? I thought it might do what I want but I'm struggling to control it. If I register it then it certainly waits until the rest of my script has run before it fires, but then it fires several thousands times back to back before stopping after a seemingly random number of fires.

How can I make it fire only once? For the timer event the object is passed in so that you can cancel it, but how do I cancel a specific OnIdle event?

Also, I've tested this whilst the file monitoring and volume analysing is going on, assuming that the event would not fire due to these tasks running, but it still fires. So when exactly is MM considered idle? Is it just when there are no scripts running code?

Any insights would be gratefully received! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Re: OnIdle

Post by Bex » Sun Jan 03, 2010 6:26 pm

I've never used it but it sounds a bit strange that it fires several thousand times. Perhaps it fires continuously when MM is idle? :)
If it would fire one time, don't you then need a OnNotIdle event? How can one otherwise know when the idle is over?
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: OnIdle

Post by trixmoto » Sun Jan 03, 2010 6:43 pm

I left it running and actually OnIdle continues to fire, it manages to fire a few hundred times between analysing the volume of each track but not during a single track by the looks of it. I don't need to know when MM is busy, I just want to say "fire once as soon as MM is idle" instead of "fire every time that MM is idle" and I can't work out how to do it. I might be able to use "Script.UnRegisterHandler" instead the Sub possibly...
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Peke
Posts: 12500
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Re: OnIdle

Post by Peke » Sun Jan 03, 2010 7:28 pm

Interesting any code samples for testing?
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: OnIdle

Post by trixmoto » Mon Jan 04, 2010 4:26 am

Well it was whilst I was working on the latest version of my "Genre Finder" script, but something like this...

Code: Select all

Sub OnStartup
  Call Script.RegisterEvent(SDB,"OnIdle","Event_OnIdle") 
End Sub

Sub Event_OnIdle()
  Call out("***OnIdle***")
End Sub

Sub out(txt)
  Dim wsh : Set wsh = CreateObject("WScript.Shell")
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim loc : loc = wsh.ExpandEnvironmentStrings("%TEMP%")
  If Right(loc,1) = "\" Then
    loc = loc&"GenreFinder.log"
  Else
    loc = loc&"\GenreFinder.log"
  End If  
  Dim logf : Set logf = fso.OpenTextFile(loc,8,True)
  logf.WriteLine(Time&" "&SDB.ToAscii(txt))
  logf.Close
End Sub
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Post Reply