在另一个线程正在运行时,通过单独的线程更新UI [英] Updating UI via seperate thread while another thread is running

查看:69
本文介绍了在另一个线程正在运行时,通过单独的线程更新UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要在另一个后台线程运行期间通过新线程更新UI。



ie



我需要在按钮点击到达下一页之前更新当前按钮的图像。



感谢

Sunny



我尝试过的事情:



Hi,

I need to update UI via new thread during another background thread is running.

i.e

I need to update image of current button before it reaches to next page on button click.

thanks
Sunny

What I have tried:

public void GoNext()
        {

            
           
            if (touchDevice != null)
                CaptureTouch(touchDevice);
                    

            //Create instance of current window data context
            var vm = DataContext as DeviceInfoViewModel;
            //if not null proceed
            if (vm != null)
            {
                // Gets the selected network adapter
                vm.AdapterDesc = Adapters.SelectedItem.ToString();

                //check if "None" is selected or not from the dropdown. 
                //If not proceed with IP configuration
                if (!vm.AdapterDesc.Trim().ToLower().Equals(Settings.Default.NONE.ToLower()))
                {
                    //sets IP config to selected adapter.
                    vm.SetIpCommand.Execute(null);
                }
                //navigate to next window on successfull completion
                Navigate();
            }
            
                      
        }

推荐答案

我可以找到sol。



I can found the sol.

await Task.Run(() =>
            {
                int progress = 0;
                for (int i = 1; i < 5; i++)
                {
                    System.Threading.Thread.Sleep(1);
                    progress++;

                }
            });





只需将代码放在我们想要执行其他任务的代码之间。



Just put above code between the code where we want to do preform another task.


这篇关于在另一个线程正在运行时,通过单独的线程更新UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆