C#外部应用程序托管 [英] C# External App Hosting

查看:126
本文介绍了C#外部应用程序托管的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#开发一个WPF程序。我需要在我的应用程序中托管外部应用程序。我也会开发这些外部应用程序。这些应用程序只包含一个窗口。我更喜欢托管一个exe文件,但加载带有代码的xaml文件也可以。它应该几乎像Windows。托管外部exe文件。但我也会开发这些外部程序。如果无法做到这一点,从这些外部应用程序加载xaml文件也会有效。我试过这个,使用Xamlreader,但我似乎无法加载cs文件(后面的代码)



如何实现这些解决方案中的任何一个?



提前谢谢

I am developing a WPF program in C#. I need to host external apps inside my application. I would also develop these external apps. These apps would only consists of one window. I would prefer hosting an exe file, but loading the xaml file with the code behind would also work. It should almost be like Windows. Hosting external exe files. But I will also develop these external programs. If that is not possible, loading the xaml files from these external apps would also work. I have tried this, using the Xamlreader, but I can't seem to load the cs file (code behind)

How can I achieve either one of these solutions?

Thanks in advance

推荐答案

我怎么看,你需要一个插件架构。那么,MEF和MAF也是WPF的选项,你可以考虑prism( http://compositewpf.codeplex.com [ ^ ])
How I see, you need a pluginn architecture. Well, MEF and MAF are options for WPF too, bou you could consider also prism (http://compositewpf.codeplex.com[^])


所以,如果你开发外部应用程序我自己认为,这已经解决了:无需外部应用程序。没有机会。



你需要开发外部单元作为类库组件,它应该实现一些插件接口。您的主机应用程序应加载所有(候选)程序集,检查它们是否真正实现了接口并使用它。如果插件建议运行一些需要花费任何明显时间的处理场景,它应该在一个单独的线程中执行。如果您不必在运行时卸载插件,这一切都非常简单。如果你需要加载,重新卸载和重载,它会使开发难度增加一倍,所以最好避免这个要求。



你可以找到全部我过去的答案涉及到什么:

通过它的字符串表示从集合中收集类型 [ ^ ],

C#Reflection InvokeMember on existing instance [ ^ ],

动态加载用户控件 [ ^ ],

使用CodeDom生成代码 [ ^ ],

AppDomain拒绝加载程序集 [ ^ ],

AppDomain拒绝加载程序集 [ ^ ]。



-SA
So, if you develop "external applications" by yourself, I think, this is settled: no external applications, ever. Not a chance.

You need to develop external units as class-library assemblies which should implement some plug-in interface(s). Your host application should load all (candidate) assemblies, check up if they really implement the interface(s) and use it. If the plug-in suggests running of some processing scenario which take any noticeable time, it should be executed in a separate thread. This is all very easy if you don't have to unload the plug-ins during runtime. If you need to load then, unload and load again, repetitively, it would more then double the difficulty of development, so better avoid this requirement.

You can find all what's involved in my past answers:
Gathering types from assemblies by it's string representation[^],
C# Reflection InvokeMember on existing instance[^],
Dynamically Load User Controls[^],
code generating using CodeDom[^],
AppDomain refuses to load an assembly[^],
AppDomain refuses to load an assembly[^].

—SA

这篇关于C#外部应用程序托管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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