简体   繁体   中英

How to call back to main thread to enable a button from a backgroundworker thread

I have a background worker that gets called to do some work and in that background worker I want to enable a Button :

myButton.IsEnabled = true;

In my UI (main thread). What do I need to do to make thecall back to the main thread to do this?

If you have access to your object from the background worker thread you can dispatch the enabling of the button to your UI thread using Dispatcher.Invoke method like this :

Application.Current.Dispatcher.Invoke((Action)delegate()
{
    myButton.IsEnabled = true;
}, 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