通过服务控制MEF按钮。 [英] Control of a MEF button through a service.

查看:96
本文介绍了通过服务控制MEF按钮。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个按钮作为单独的应用程序的mef插件,并由该应用程序的视图模型显示。我还需要能够从Windows服务控制这些按钮的状态和切换。可能,我在哪里可以看?使用.Net 4.0

解决方案

这个问题太模糊了,无法给出确切的建议。您没有描述您现有的架构以及您尝试过的内容。你没解释什么可能是你的问题。



但这个想法可能是这样的:你应该记住,即使没有桌面,你的Windows服务仍然有效,所以没有任何UI应用程序存在。因此,您需要的协作应该由您的UI应用程序的主动建立,该应用程序符合客户端 - 服务器的概念。



您必须创建一些网络,或者更合适的是,Windows服务中的IPC服务。它可以使用套接字或命名管道直接完成,或者在更高级别上使用Windows服务中托管的经典远程处理或WCF。 UI应用程序应该能够连接到服务(可能是在他们的startop上并在终止之前断开连接)并订阅一些服务事件(无论你需要介绍什么)。在这些事件的处理程序中,UI应用程序可以更改按钮的状态或您需要更改的任何内容。服务器应该保持对UI行为的不可知。这样,您将支持松散耦合并避免强耦合,这在这种情况下非常重要。



另请参阅:

http://en.wikipedia.org/wiki/Loose_coupling [ ^ ],

http://en.wikipedia.org/wiki/Coupling_(computer_science) [ ^ ]。



-SA

I have several buttons that are mef plugin's to a separate application, and are displayed by that apps' view model. I need to also be able to control the status and toggle of those buttons from a windows service. Possible, and where can I look? Using .Net 4.0

解决方案

The question is way too vague to give the exact advice. You did not describe your existing architecture and what have you tried. You did not explain what could be your problem.

But the idea could be this: you should remember that your windows service works even if there is no a desktop, so none of the UI applications even exist. So, the collaboration you need should be established by the initiative of your UI application, which is inline with the concept of "client-server".

You have to create some network or, more appropriately, IPC service in your windows service. It could be done directly using sockets or named pipes, or, on a higher level, using "classic" remoting or WCF hosted in your windows service. The UI application should be able to connect to the service (presumably, on their startop and disconnect before their termination) and subscribe to some service events (whatever you need to introduce). In the handlers of those events, the UI application can change the states of the buttons or whatever you need to change. The server should remain agnostic of the UI behavior. This way, you would support loose coupling and avoid strong coupling, which is very important in this case.

Please see also:
http://en.wikipedia.org/wiki/Loose_coupling[^],
http://en.wikipedia.org/wiki/Coupling_(computer_science)[^].

—SA


这篇关于通过服务控制MEF按钮。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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