Fish in the river

思考 技术
记录 回忆
  1. Main page
  2. 软件开发
  3. C#
  4. Main content

wpf 使用CommunityToolKit.Mvvm实现多线程

2024年2月7日 177hotness 0likes 0comments

接上一个文章,我们在上一个文章中使用CommunityToolKit.Mvvm写了命令。我们在这篇文章中,写一下MVVM模式下的多线程。

在开发过程中,不可避免的会使用到多线程,用以提高程序运行的响应性。在这个过程中就会碰到在另一个线程中操作UI线程中的控件。

这时必须要用到WPF的多线程线度调度器“Dispatcher”。这个相对于在Winform中的使用,已经简单了许多了。

但是和大神的文章相比,我发现CommunityToolKit.mvvm中没有DispatcherHelper这个类。我找了很久,也没有找到,所以还是只能使用Dispatcher这个WPF中的原生的类来实现了。

还是那句老话,写程序一定要用成熟的技术。千万别用一些小众的框架。要不,到时有你受的。

同上篇文章,这篇文章的实现来自这位大神的文章。我只是将他原来使用mvvmLight的框架使用CommunityToolKit重新实现了一遍

大神的文章如下。

https://www.cnblogs.com/wzh2010/p/6518834.html

重写的Demo源码如下。在Visual studio2022 + .net 6.0下编译实现。

立即下载
Tag: C#
Last updated:2024年2月7日

joey

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

Comments

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
Cancel

归档

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024

分类目录

  • C#
  • Dock
  • Excel
  • Kindle
  • Linux
  • Windows
  • 生活感悟
  • 群晖
  • 运维技术

COPYRIGHT © 2024 水中小鱼. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang