1
votes

I have a tree view with a simple tree in it.
I have a pretty simple question about how to solve a problem I have.

Once the user selects a new tree item, I am running a small process in the background using the SelectedItemChanged event. The process takes anywhere from half a second to 1.5 seconds max.

The problem is that the GUI then seems to be running slow. The tree item that is selected outgoes get highlighted blue until the process running in the background is done executing.

I think it will make the GUI appear to run smoother if I can some how run the process after the tree item is highlighted blue. To the user they visually see that they changed the item and by the time they see the item change the process will probably be done executing.

Does anyone know how to do this?

1

1 Answers

2
votes

Spawn the process in the "SelectedItemChanged" event in a new thread:

Task.Factory.StartNew(() => 
{ 
    // your code // 
};

If you need to refer to UI objects within that process, you will need to use the correct dispatcher call access them:

Dispatcher.BeginInvoke(new Action(() => { // ui thread tasks here // };