如何运行循环异步,因此它不会挂起UI [英] How to run for loop async so it doesn't hang the UI

查看:76
本文介绍了如何运行循环异步,因此它不会挂起UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用bing地图导航API来绘制行车路线。我需要使用for循环来获得lat long路径。现在,当我输入长路径时,for循环挂起UI,因为它必须循环超过大限制,那么我怎么能停止挂起UI呢?我尝试了
使用Dispatcher.RunAsync()但没有工作,也尝试过Task.Run()但它抛出错误"应用程序调用了一个为不同线程编组的接口"。我需要更好的解决方案,所以它循环并绘制路线。

Hi, I am using bing map navigation API to draw driving route. I need to use for loop for getting the lat long of route. Now the for loop hangs the UI when I enter the long route as it has to loop over large limit, so how can I stop hanging the UI ? I tried using Dispatcher.RunAsync() but not working, also tried Task.Run() but it throws error "The application called an interface that was marshalled for a different thread". I need better solution so it loops through and draw the route.

推荐答案

你能发布你目前的代码吗?
Can you post the code you have currently?

这篇关于如何运行循环异步,因此它不会挂起UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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