Threads in Windows Media Center

Currently, Windows Media Center applications are hosted in an individual ehExtHost.exe process. Applications running on prior versions of Windows Media Center ran concurrent with the Windows Media Center process (ehShell.exe) in their own application domain. Windows Media Center runs each background application in a separate thread, and the application can create as many threads as it needs. Because foreground threads can prevent the application from terminating properly, a multithreaded application should use background threads whenever possible by setting the thread IsBackground property to true.

An application can create as many threads as it wants. However, the Windows Media Center object model is single-threaded. You cannot construct a ModelItem or raise change notifications from a thread other than the main application thread. (Although it is more difficult, you can create a model item using the IModelItem interface to run on a different thread.) Most of the methods in the Microsoft.MediaCenter.UI namespace can only be called from the main application thread, with the exception of the methods in the Application class.

The methods in the Microsoft.MediaCenter, Microsoft.MediaCenter.Hosting, and Microsoft.MediaCenter.ListMaker namespaces can be called on any thread, but some of them may block if the main application thread is blocked. Callbacks are supported only on the main application thread.

The methods in the Microsoft.MediaCenter.TV.Epg and Microsoft.MediaCenter.TV.Scheduling namespaces can be called on any thread or on as many as needed. Events are called back on the same thread as you called them from.

Note Windows Media Center can host up to eight instances of ehExtHost.exe—for instance, if a user presses the Green Start button when navigating third-party applications and starts an application multiple times. If an application needs to share state across instances of ehExtHost.exe, you must implement your own way of determining that another instance of the application is running on the system.

A Windows Media Center application can implement all of the functionality it needs, or it can communicate with separate executables outside of Windows Media Center to implement certain tasks. For example, a Windows Media Center application could be used to manage a process for downloading or retrieving content while Windows Media Center is running, or it could rely on a separate executable running in Windows to retrieve content even when Windows Media Center is not running. Conversely, external applications running outside of the Windows Media Center process can use Windows Media Center applications to access the Windows Media Center object model.

Sample Explorer

  • Code and Data > Threading - Code
  • Code and Data > Threading - MCML

See Also