Create a WPF “control” that is run in an external

2020-07-29 02:13发布

I have a WPF app which contains a number of child controls.

One of these controls hosts a third party library which underneath the covers runs some native code which throws access violations and crashes the application. Unfortunately removing the library is not an option.

What I'd like to do is spin up a new windows process, host the third party library inside that, and somehow communicate with it. Much in the same way that Google Chrome and IE8 handle browser plugins.

The issue is that the third party library needs to draw to the screen, so I have to somehow have the equivalent of an HTML iframe inside my WPF app's main window.

I'm not sure how to get started on this, it's proving difficult to google for thus far. Any advice is greatly appreciated.

3条回答
该账号已被封号
2楼-- · 2020-07-29 02:46

This is a tough one, but fortunately for you there is a little work being done in this space lately.

Have you heard of the System.Addin namespace in .NET 3.5? It could probably help in this case. It allows for controls to be loaded in a separate AppDomain, but be displayed in the same UI. I'd imagine you'd have to do a little bit of work to get everything communicating properly (never done this before), but it's possible.

Have a look at this early post from the Add-in team: http://blogs.msdn.com/clraddins/archive/2007/08/06/appdomain-isolated-wpf-add-ins-jesse-kaplan.aspx

Seems like they keep their samples and helper code on codeplex: http://clraddins.codeplex.com/

I'm very interested in this, so if you get this working, let us know how this went for you!

查看更多
Juvenile、少年°
3楼-- · 2020-07-29 02:54

Coming in way late. If you still need this, have you seen this project: https://docs.microsoft.com/en-us/archive/blogs/changov/hosting-wpf-ui-cross-thread-and-cross-process

I'm running multiple plugins in multiple external processes in my LOB app. My framework grew out of the project above.

查看更多
做自己的国王
4楼-- · 2020-07-29 03:06

Probably not the easiest of tasks. Have you considered hosting your 3rd party stuff in a separate App-Domain? That way you will also get a good level of isolation while saving you the hassle of another project. Does it have to be refreshed constantly or could you refresh at predefined points in your application? Maybe some scheme where you basically do a screenshot of the 3rd party output and show it as image in your original app would then be possible...

查看更多
登录 后发表回答