Best and simplest:
using(var d = Dispatcher.DisableProcessing())
{
/* your work... Use dispacher.begininvoke... */
}
Or
IDisposable d;
try
{
d = Dispatcher.DisableProcessing();
/* your work... Use dispacher.begininvoke... */
} finally {
d.Dispose();
}