You've run into a bug in Add-in Express. In some cases Add-in Express event handlers are called with System.Threading.SynchronizationContext.Current
set to null
. BackgroundWorker
use it in RunWorkerAsync
method to save the ui context, so that is the problem.
To fix SynchronizationContext you could use the following workaround. Here MyAction
is the method where you call RunWorkerAsync
from.
var ctx = SynchronizationContext.Current;
if (ctx != null)
{
MyAction();
}
else
{
var timer = new DispatcherTimer();
timer.Tick += (s, a) =>
{
MyAction();
timer.Stop();
timer = null;
};
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Start();
}
Another solution would be saving the valid SynchronizationContext.Current
value somewhere in a static member and then calling SynchronizationContext.Post
in the event handler for the same purpose. I haven't tried this one though.