在 WPF 中使用 ReactiveUI 从长时间运行的命令提供反馈的正确方法 [英] Proper way to provide feedback from long-running command using ReactiveUI in WPF

查看:27
本文介绍了在 WPF 中使用 ReactiveUI 从长时间运行的命令提供反馈的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C#/WPF/.NET 4.5 应用程序,用户将使用它打开某些文件.然后应用程序将经历很多动作 - 读取文件,通过许多插件和解析器传递它.这些文件可能相当大 (>100MB),因此这可能需要一段时间.我想让用户了解 UI 中发生的事情,所以在我的视图模型中,我有一些东西可以显示当前状态和进度条.

I have a C#/WPF/.NET 4.5 app that users will use to open certain files. The app will then go through a lot of motions - read the file, pass it trough a number of plugins and parsers. The files are potentially fairly big (>100MB) so this could take a while. I want to keep the user informed about what is going on in the UI, so in my viewmodel I have some stuff for showing current status and a progress bar.

现在我想变得很酷和现代,并使用 ReactiveUIs 异步命令支持来做到这一点,这对我来说是全新的.

Now I want to be cool and modern and do this using ReactiveUIs Async command support, which is completely new to me.

对于来自加载/解析过程的反馈消息,最好的方法是什么?状态消息和进度条 val/max 值需要在 UI 线程上设置,非常基本的东西.我应该将我的数据加载器实现为 IObservable,还是使用 MessageBus 组件来执行此操作是否更好?

For the feedback messages from the load/parse process, what is the best approach? The status message and progress bar val/max values need to be set on the UI thread, pretty basic stuff. Should I implement my data loader as an IObservable, or is it somehow better to do this using for instance the MessageBus component?

请记住,用户可能会同时将多个这样的大文件加载到应用中,我希望用户界面在加载过程中尽可能保持响应.

Keep in mind that a user might be loading several of these huge files into the app at once, and I want the UI to remain as responsive as possible while the loading is going on.

非常感谢如何正确实施此操作的示例!

Examples of how to go about implementing this properly would be hugely appreciated!

推荐答案

我在别处与大师本人 (Paul C. Betts) 核对过,他告诉我处理这个问题的方法是使用显示用于创建 Subject 的进度信息并将其传递给进行实际加载/解析的人员.然后这些可以使用 .OnNext() 将新信息推送到主机.

I checked this with The Master himself (Paul C. Betts) elsewhere, and he told me that the way to handle this would be for the app that displays the progress information to create a Subject<SomeProgressInfo> and pass this to the guys doing the actual loading/parsing. These can then push new information to the host using .OnNext().

这也有助于单元测试,其中可以只提供一个虚拟的 Subject;不会订阅.

This also helps with unit testing, where one can just provide a dummy Subject<T> that won't be subscribed to.

这篇关于在 WPF 中使用 ReactiveUI 从长时间运行的命令提供反馈的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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