views:

220

answers:

4

I have a wpf application that takes ~30 seconds to create a map/graphic. I have read there is no easy way to tie into the UI rendering thread to get a progress update. So I was going to use a counter on a value converter which colors my map but that is also on the UI Thread, so my question is has anyone found any slick methods of working with the rendering thread yet?

Thanks.

+3  A: 

You could create your map/graphic in a BackgroundWorker which allows you to call ReportProgress in your function, where you can set your percentage of completion and raise the ProgressChanged event to update your UI.

smoore
Agreed on another thread +1.
Anvaka
Sorry, I forgot to mention I am generating my map/graphic in XAML using binding. Correct me if I am wrong but in this case I can't use a background worker because the map is rendered in the hidden rendering thread correct?
Nathan
A: 

Hi Nathan.

When you say UI rendering thread, you mean that hidden rendering thread from WPF internals or UI thread?

In any case, having a separate thread that builds your map and notifies UI about progress doesn't help you?

Anvaka
A: 

Hi Nathan,

im not sure if this is what you are looking for.

I use something similar to the code below to load in around 300 images( about 200 mb ) and have no UI slow down at all. (the user can see each image being loaded in, I just keep an empty placeholder image up till the final image is loaded)

The images are loaded in a background thread, and then the function is called to actually put them into the WPF scene.

here is a simple example using a textbox. You can call this function from any thread and it will work out if it needs to change the to the GUI thread. (for my project of course i am doing it with bitmaps, not a textbox ).

    delegate void UpdateUIThreadDelegate(String str);

    public void DisplayString(String strMessage)
    {
            if (this.InvokeRequired)
            {
                UpdateUIThreadDelegate updateDelegate = DisplayString;

                this.BeginInvoke(updateDelegate, strMessage);

                return;
            }

            myTextBox.Text = strMessage;
    }

Cheers Anton

antonwinter
A: 

Hi,

If you use binding to tie your UI with a datasource which can take long time to return, you can set 'IsAsync=True' on your binding so that the binding become asynchronous.

If you want to display some other datas (even an animation I guess) during the time your datasource is loading, you can use a PriorityBinding

HTH

Riana

Riana Rambonimanana