NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 49 50 51 52 53 … 93 Next »
InvalidOperationException - getPluginHelper().AddAudioFileToQueue(string file)

 
  • 0 Vote(s) - 0 Average
InvalidOperationException - getPluginHelper().AddAudioFileToQueue(string file)
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#1
2006-09-24, 04:50 AM
Help sub.

On 98.8b after a problem was reported to me on my music library. I get this error when a timer I run, grabs some mp3 tracks and trys to add then to the playlist.

The error shows up in my debugger as:
Code:
Cross-thread operation not valid: Control 'HomeMenu' accessed from a thread other than the thread it was created on.

Before 98.8 this was working - I don't know when the behaviour changed.

Some more details. The main class on my plugin (not the task class) is a static. When it starts, it creates a timer to use for updating the music database, and a random (jukebox mode) music queue after a period of inactivity.

When i perform the same action that it's trying to perform (a random queue of music) with the keyboard, it's fine. The only time the problem occurs is when the timer event is fired off, and it tries to create random music from there.


Are there any suggestions you can offer as to what might be the cause/resolution. I'm not too up on multi-threading......

I've just added a stack trace to give a bit more information...
Code:
MusicLibrary2: Generating a random playlist of 60 length
MusicLibrary2:  Adding tracks to pluginHelper
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
MusicLibrary2: Error Adding random tracks to playlist
Cross-thread operation not valid: Control 'HomeMenu' accessed from a thread other than the thread it was created on.
   at System.Windows.Forms.Control.get_Handle()
   at NativeUtilities.MediaHelper.playMusicFile(String filename, Form form)
   at GBPVR.x62b73fb0db4f3947.x826e5d374a1e5ab9(String x8b449efd64797843, Boolean x859a785ef30c9007, Boolean xe1ea8da9364d6bfb)
   at GBPVR.x62b73fb0db4f3947.x826e5d374a1e5ab9(String x8b449efd64797843)
   at GBPVR.x62b73fb0db4f3947.x313dba8d86564907(Queue x67c4bec203dc37ec)
   at GBPVR.xbb1566157f5f8b1f.AddAudioFileToQueue(String file)
   at MusicLibrary.MediaLibrary.RandomPlaylist(String primary, String secondary, Int32 minutes) in D:\Documents and Settings\David\My Documents\Visual Studio Projects\GBPVR\C#\MusicLibrary2\MediaLibrary.cs:line 3083
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,698
Threads: 767
Joined: Nov 2003
#2
2006-09-24, 05:06 AM
I'm not really sure how your timer works, but you can only call AddAudioFileToQueue() from the main thread. This has been discussed a couple of times in the past.

The .net 2.0 builds would give you this error, but you shouldnt have been calling this method even on the older v1.1 releases of GB-PVR.
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#3
2006-09-24, 05:08 AM
Hmm, maybe it's just a dev/VS2005 thing, I tried the same dll just running in GBPVR and it doesn't have the same problem....
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#4
2006-09-24, 05:11 AM
sub Wrote:I'm not really sure how your timer works, but you can only call AddAudioFileToQueue() from the main thread. This has been discussed a couple of times in the past.

The .net 2.0 builds would give you this error, but you shouldnt have been calling this method even on the older v1.1 releases of GB-PVR.

That AddAudioFileToQueue has been around a while hasn't it?? Or am I reading your comment wrong?? Is there something else I should be using.

I don't "try" to do anything multi-threaded, but I figure the timer (System.Timer.Timer) is probably doing that anyway...

Hmm, this might make things hard to debug, if it only does it in development...
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,698
Threads: 767
Joined: Nov 2003
#5
2006-09-24, 05:11 AM
Quote:I don't "try" to do anything multi-threaded, but I figure the timer (System.Timer.Timer) is probably doing that anyway...
Yeah, I'm pretty sure your timer is a thread behind the scenes.

I'm sure the exception is warning you that you shouldnt be doing this.

The problems relate to using the Windows Media Player object, which can only be accessed from the thread that created it.
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#6
2006-09-24, 05:18 AM
Can you think of any suggestions as to how I should be doing it? Or be able to point me in the right direction?

I did see some stuff about call back methods and async methods, but don't really know if they relate...
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,698
Threads: 767
Joined: Nov 2003
#7
2006-09-24, 05:22 AM
I'm not quite sure exactly what you're doing with that timer, but could you be adding to some queue in background, but only submitting that queue from the foreground thread? Or does your plugin not necessarily have control at the time (ie, not the active plugin on the screen)?
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#8
2006-09-24, 05:36 AM
The timer is used for the database update, so it is started when the plugin is instanciated (but it hasn't necesarily had IMenuTask.Activate() called). It also calls this AddAudioFileToQueue after a certain time period (the user has to have activated the plugin and be just sitting on the plugin's main screen to for it to run).

The IMenuTask class for my plugin just accesses the "media library" class as a static (I know you're probably cringing about now :o )

So would that technically make it a background thread?
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#9
2006-09-24, 05:47 AM
Maybe I'm making a mountain out of nothing. I don't seem to get these errors when I start GBPVR.exe by itself, and not run it in debug...

Ta for the chat... Big Grin
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,698
Threads: 767
Joined: Nov 2003
#10
2006-09-24, 07:24 AM
Quote:The IMenuTask class for my plugin just accesses the "media library" class as a static (I know you're probably cringing about now :o )

So would that technically make it a background thread?
Its not this that is making it a background. It is how this timer you are using is implemented. It probably runs as a background thread calling one of your methods periodically.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (2): 1 2 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  How Does "Use S01E01 File naming format if possible" work puck64 7 5,316 2015-08-25, 10:21 AM
Last Post: puck64
  NEWA - using buffer file produced by /public/VLCService?Channel= bgowland 5 2,794 2014-01-02, 06:36 AM
Last Post: bgowland
  Is the input file for pvrx2.exe -import unique to NextPVR? spinnaker 1 1,768 2013-10-08, 02:25 AM
Last Post: sub
  Accessing music file metadata in C# bgowland 6 3,289 2013-01-26, 05:14 AM
Last Post: bgowland
  File browsing - a big ask imilne 3 1,990 2010-11-04, 09:03 PM
Last Post: imilne
  Run Multiple File Conversions On Your 4 Core -Burn Your Processor luttrell1962 12 4,575 2010-03-25, 07:33 AM
Last Post: luttrell1962
  Using Windows file system shortcuts ACTCMS 0 1,802 2010-01-26, 11:45 PM
Last Post: ACTCMS
  Not looking in correct location for skin file scb147 4 2,212 2009-07-29, 06:26 PM
Last Post: scb147
  PlayAudioFile() 0KB file bug bgowland 1 1,567 2009-04-25, 09:27 PM
Last Post: sub
  Uninstalling VS breaks .hta file association bgowland 0 1,576 2009-04-09, 07:45 PM
Last Post: bgowland

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

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

Linear Mode
Threaded Mode