简体   繁体   中英

Doing series of actions without blocking UI Thread

I want to do a series of actions and simultaneously depend on exception it throw or doesn't throw any exception update my UI, how can I achieve something like this?

I've already tried making new thread for each step but it doesn't wait until one of steps ends and it writes fail message always, using Thread.Join() didn't help either because it blocks UI thread too...

You need BackgroundWorker . Put the code you want to execute in background thread in DoWork handler and code of updating UI in RunWorkerCompleted event handler.

In case you want to update GUI in between from DoWork handler, you can queue it on UI dispatcher like this -

App.Current.Dispatcher.BeginInvoke((Action)delegate
        {
           // Update GUI here.
        }, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM