INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Help with MC's threading model  (Read 1326 times)

muchadhesion

  • Recent member
  • *
  • Posts: 44
Help with MC's threading model
« on: April 29, 2010, 01:49:47 pm »

Hello,

I'm trying to track down some "UI hangs" when using MC with my plug-in.  Specificaly, I have a System.Windows.Forms.Timer(); that is scheduled to go off every 3 seconds, but sometimes the UI freezes, and the timer is not triggered for many seconds.

Currently I only have suspicions about what is causing the MC UI to become unresponsive.  My primary suspicion is that MC assumes certain APIs from the plug-in SDK are called from the "correct" thread.  Calling some MC APIs in the "wrong" thread results in wierd stuff happening.  Specifically, the UI is more likely to "hang".

As a result, much of my plug-in is wrapped in Winform InvokeRequired/Invokes to push processing into the main UI thread.  The only API that is not wrapped religiously is GetActiveZone().

Some questions, (bare in mind I'm not a windows expert):
* Does MC assume plugins are run in a multi-threaded appartment, or single threaded appartment?
* What threads does MC have, and are there restrictions on when/where MC plugin APIs are called?
* It is possible that the behaviour I'm seeing is not being caused by my plug-in at all - my media lives on a network drive, and the "UI freezes" happen more often during scanning, and building thumbnails.  Is it possible that MC's UI sometimes wedges waiting for completion of extensive network activity?  Does anyone else experience this sort of behaviour?

I've done alot of experimentation trying to isolate the problem - I'd appreciate any insight or pointers from others...

Many thanks
m



Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41932
  • Shoes gone again!
Re: Help with MC's threading model
« Reply #1 on: April 29, 2010, 02:00:06 pm »

In general, any database operation is safe to call from a worker thread (by using an unmarshalled COM automation pointer, etc.).

Any operation that starts playback, or uses the user interface should use marshalled automation pointers so that you're calling in the main thread.

If you're seeing pauses, you might consider pressing 'Pause' in the debugger during a stall and looking at the list of threads and seeing if the main thread is in your code.

Media Center uses lots of threading, but it does have some operations and timers that run in the main thread.  We try to make sure none of those main thread things could cause hiccups (or they get moved to worker threads), but it's possible you're encountering a special case.

During especially high threaded activity (thumbnailing images, importing, serving DLNA, maybe all at once) main thread operations could bog down on a slower machine, even if nothing is really blocking the main thread.
Logged
Matt Ashland, JRiver Media Center

muchadhesion

  • Recent member
  • *
  • Posts: 44
Re: Help with MC's threading model
« Reply #2 on: April 30, 2010, 06:10:08 am »

Great info, (again).  Many thanks.  I'll report back if I discover anything of interest.
Logged
Pages: [1]   Go Up