0

In my silverlight 4.0 application, at one point, after user pushes a button, I have to create few UI objects that take some time (5-10seconds). During this time UI freezes of course. I decided to put creation of those objects in a background worker so UI could at least show progress bar.

But this solution does not work. To create UI object you have to be in UI thread. If I put creation of those object inside Dispatcher.BeginInvoke() than again my UI freezes. In most cases without even showing progress bar. Is there a way around this?

Can I show progress bar while silverlight creates UI objects in the background?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
grabah
  • 165
  • 2
  • 16

2 Answers2

0

Have a look at this forum post. It may help.

Instead of using:

System.Windows.Threading.Dispatcher.BeginInvoke(() => {});

They use:

System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => {});
DJH
  • 2,191
  • 4
  • 28
  • 45
0

You can try displaying a custom message before creating UI objects inside BeginInvoke().

Example:

private void CreateObjects()
{
    myMsg.Text = "Loading...";
    Dispatcher.BeginInvoke(() => { AddObjects() });
}

Once all objects are created, disable the message.

You can try the similar thing with Progress Bar also.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Vivek
  • 1,823
  • 1
  • 19
  • 39
  • yes, but to display myMsg you need to access UIThread, and if objects are created on the same thread Ui wont have time to update – grabah Jul 24 '12 at 08:41
  • What I was trying to say here is instead of Progress Bar you can show a message while the update is in progress. Offcourse you need to be in the UIThread to do it. BTW, did you try this? – Vivek Jul 25 '12 at 11:25