简体   繁体   English

如何在显示窗口之前使WPF / MVVM应用程序进行后台处理?

[英]How do I make a WPF/MVVM application do background processing before displaying a window?

I'm fairly new to WPF & MVVM. 我是WPF和MVVM的新手。 I've created a couple standard simple WPF/MVVM applications that show a startup screen and do processing, including displaying other user controls, based on commands within that main window. 我已经创建了几个标准的简单WPF / MVVM应用程序,它们基于该主窗口中的命令显示启动屏幕并进行处理,包括显示其他用户控件。

But now I want to make a WPF/MVVM monitoring/input-gathering application that starts up without displaying a window, loops through checking the system state until conditions necessitate the window's display, and only THEN displays a window, then processes the user input and goes back to looping. 但是现在我想制作一个WPF / MVVM监视/输入收集应用程序,该应用程序在不显示窗口的情况下启动,循环检查系统状态,直到有条件需要显示窗口为止,然后只有THEN显示窗口,然后处理用户输入并回到循环。 The user wouldn't be waiting for this window, because it's only shown when there's something that needs the user's attention. 用户不会等待此窗口,因为仅当有需要用户注意的内容时才会显示该窗口。 It would run in the background "forever", only showing itself when needed. 它会在“永远”的背景下运行,仅在需要时显示。

I see that I can make my own Main() method, but I still can't figure out the best way to keep it in MVVM, yet only display the window as needed within a larger loop. 我看到我可以制作自己的Main()方法,但是我仍然想不出将其保存在MVVM中的最佳方法,但是只能根据需要在更大的循环中显示窗口。

Thanks! 谢谢!

EDIT - we finally did the sane thing and made two different processes, one to do the monitoring and one to do the WPFing. 编辑-我们终于做了明智的事情,并进行了两个不同的过程,一个过程进行监视,另一个过程进行WPFing。 Thanks all! 谢谢大家!

A Windows Service seems to be the best way to do the monitoring. Windows服务似乎是进行监视的最佳方法。 As soon as user interaction is needed you could signal the rest of the 'world' that something has occured. 一旦需要用户交互,您就可以向“世界”的其余部分发出信号,表明已经发生了某些事情。

A WPF client could pick up the signal and show a UI. WPF客户端可以接收信号并显示UI。 The WPF client could be hidden by using a NotifyICon. 可以通过使用NotifyICon隐藏WPF客户端。

MVVM would only be appropriate in the WPF Client. MVVM仅适用于WPF客户端。 The model contains the status that is monitored, the viewmodel turns this into a model of the view and the view displays the information. 该模型包含受监视的状态,该视图模型将其转换为视图的模型,并且该视图显示信息。

The signal could be a Mutex that is set by the service and tested by the WPF client. 该信号可以是由服务设置并由WPF客户端测试的Mutex Communication between the service and the client could be implemented by using WCF. 服务和客户端之间的通信可以通过使用WCF来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM