Hey all

I'm having trouble updating my ui across threads using WPF. Having learnt a fair deal about thread yesterday, I find myself stumped now by the Dispatcher. I've already used the dispatcher once, to check the status of a radio button, as follows:

if ((Boolean)this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new noArgsDelegate(productIsChecked)))
            {
                //...do some work...
            }

...with productIsChecked looking as follows:

private Boolean productIsChecked()
        {
            return (Boolean)radProduct.IsChecked;
        }

This worked nicely. Then, in an attempt to change the status of one of my tab items (placing a graph as the contents), I tried the following:

this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new noArgsDelegate(setGraph));

...where setGraph() looks as follows:

private Boolean setGraph()
        {
            try
            {
                GraphArea.Content = c;
                MessageBox.Show("Graph Set");
                return true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return false;
            }
        }

(Sorry there's so much code. Just wanted to give a full idea of what's going on) When I run this, I get a TargetInvocationException. Suspecting what was happening, I stuck in the try catch you can see, and, as I expected... I was getting an InvalidOperationException. I can't change the content of the GraphArea since it belongs to another thread... but I thought the Dispatcher dealt with this... Any idea of what's going wrong, or how to fix it?

Thanks
M

Hey don't worry, a friend of mine can sort this out for me. Thanks for all the help though, I appreciate it. Not sure I like the Dispatcher much anymore lol

Thanks
M

This article has been dead for over six months. Start a new discussion instead.