سؤال

Why my Dispatcher.Invoke action is not being rendered instantly? It's bugging me

        Dispatcher.Invoke((Action)(() => busyIndicator1.BusyContent = loaderComment), System.Windows.Threading.DispatcherPriority.Send);

        var sw = new Stopwatch();

        sw.Start();
        var newItems = func.Invoke(Operation);
        sw.Stop();

My new busyIndicator1.BusyContent value is rendered only after my Func func finishes execution, and func takes a while. I have already set low priority to all my other Dispatcher.BeginInvoke calls.

هل كانت مفيدة؟

المحلول

You are blocking the thread responsible for the operation you dispatch with your function call. The dispatcher queue (at least the GUI rendering part) is not processed until you let the thread idle again (i.e. the method/event handler whatever is exited).

Do your function execution on another thread.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top