0

My app calculates the Image of the StyledStringElement and this process takes a good amount of time. It's all done locally.

How can I do something like this pseudo code:

myElement.Image = PlaceHolderImage; 
myElement.GoGetTheImageFromSomeLongRunningTask = GetImageFromSomeFuntionThatWillTakeTime();
Ian Vink
  • 66,960
  • 104
  • 341
  • 555

1 Answers1

2

You can use something like this (not tested):

myElement.Image = PlaceHolderImage;
ThreadPool.QueueUserWorkItem ((v) =>
{
    var image = GetImageFromSomeFunctionThatWillTakeTime ();
    BeginInvokeOnMainThread (() =>
    {
        myElement.Image = image;
        myRoot.ReloadData ();
    });
});

Note that this assumes that GetImageFromSomeFunctionThatWillTakeTime can actually be executed on a secondary thread. You can easily test this by using the current MonoTouch beta (5.3.2), since you'll get an exception if you do something that's not allowed on a secondary thread.

Rolf Bjarne Kvinge
  • 19,253
  • 2
  • 42
  • 86