When I need to perform an action that takes quite long, I call it in a BackgroundWorker like this, so it does not freeze the UI;
BackgroundWorker bgWorker = new BackgroundWorker();
bgWorker.DoWork += (s, e) => {
//Do something long lasting
for(int i = 0; i < x; i++){
//Performing action i of x
//While doing so update the progressbar
prgBar.Dispatcher.Invoke(() =>{
prgBar.Value += ((i / x) * 100.0);
});
}
};
bgWorker.RunWorkerCompleted += (s, e) => {
//Finish up things
};
bgWorker.RunWorkerAsync();
Is this 'the way to go' to update the UI or is it 'not done'? The same question applies for the BackgroundWorker (Maybe just start a new thread instead of a BackgroundWorker?)