WPF MVVM模式下的无阻塞
卡顿的原因:
异步请求数据列表,数据列表响应后,加载数据和图片,(UI)图片请求远程路径延时导致卡顿;
解决方案:异步处理下载图片,然后让UI显示;
if (ImgUrl.Contains(".png") || ImgUrl.Contains(".jpg") || ImgUrl.Contains(".gif")) { string fileName = ImgUrl.Substring(ImgUrl.LastIndexOf("/") + 1, ImgUrl.Length - ImgUrl.LastIndexOf("/") - 1); string fileType = ImgUrl.Substring(ImgUrl.LastIndexOf(".") + 1, ImgUrl.Length - ImgUrl.LastIndexOf(".") - 1); string savepath = String.Format("{0}\\hitool\\Users\\{1}\\download\\", Environment.ExpandEnvironmentVariables("%systemdrive%"), Globle.TEMP_USER_SETTING.Username); if (!Directory.Exists(savepath)) { Directory.CreateDirectory(savepath); } savepath += fileName; if (File.Exists(savepath)) { } else { } }
Dispatcher.Invoke 和 Dispatcher.BeginInvoke 是子线程调度到主线程去运行;如果允许耗时,会造成界面假死;
不阻塞UI的多线程方法
https://blog.csdn.net/hujianwind/article/details/5181985
WPF MVVM模式下的无阻塞刷新探讨
https://www.cnblogs.com/yzp12sina/p/3512265.html
https://blog.csdn.net/weixin_30354675/article/details/97297866
WPF非阻塞UI弹出窗口
https://www.thinbug.com/q/55090368
https://www.cnblogs.com/RMay/archive/2009/09/02/1559035.html
C#-等待DbContext时WPF UI阻塞
https://www.icode9.com/content-1-566273.html
六种多线程方法解决UI线程堵塞
https://blog.csdn.net/swarb/article/details/17357011?utm_term=wpf%E9%98%BB%E5%A1%9Eui%E7%BA%BF%E7%A8%8B&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-1-17357011&spm=3001.4430
WPF中UI线程频繁操作造成卡顿的处理(一)
https://www.jianshu.com/p/1d19514bccea