Search code examples
windows-phone-7functionexecution

Waiting the function to be done in windows phone


There is a function like this:

public MImage ImageHandler (parameter){
    // do something
}

This function will take some time depending on the parameter, now I want to monitor the execution of this function and do something after the function is done, like this:

//call this function
Task task = new task(ImageHandler(parameter));
task.begin();
task.done +=(()={ // do something after the function is done});

So How can I make it out?

Thanks in advance.


Solution

  • You can run your code that takes some time to execute on a background thread using a BackgroundWorker

    See: How to use a BackgroundWorker

    The code that you want to run after the task has been complete can be placed in teh handler for the RunWorkerCompleted event.