Untitled
Well, here is the code that I am using : as you can see I initialize a ManualResetEvent to put the tread into wait state.
Another thread is instanciated to receive keyboard hooks. With this code, and I know that several Media Center plugins are based on this (code has been written by Stephen Toub from MS when he posted the code of its addin PositionChangerAddin),
you will realize that after a while you loose access to the MediaExperience data.
public void Launch(AddInHost host)
{
// Store the host for use during this session
_host = host;
try
{
// Initialization code
...
// When Launch returns, the add-in is unloaded, so use an MRE to keep it around until
// MCE says it using (_waitForExit = new ManualResetEvent(false))
{
using (_timer = new System.Threading.Timer(new TimerCallback(UserEntryTimeout), null, Timeout.Infinite, Timeout.Infinite))
{
logger.Log(Level.Debug, "Initializing the remote control or/and keyboard hooks...", null);
// Install a keyboard hook for the process
_waitForExit.WaitOne();
}
}
}
catch (Exception e)
{
logger.Log(Level.Error, "Error in the background addin", e);
}
}
Regards,
Damien BT