WPF MVVM模式下的无阻塞

卡顿的原因:
异步请求数据列表,数据列表响应后,加载数据和图片,(UI)图片请求远程路径延时导致卡顿;
解决方案:异步处理下载图片,然后让UI显示;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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

 

posted @   microsoft-zhcn  阅读(533)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示