如何通过托管进程服务非托管线程 [英] How to serve unmanaged threads via a managed process
问题描述
试图设计类似ASP.NET的东西,但需要进一步了解如何进行编程/设计.
将有很多非托管线程需要由托管进程(DLL)提供服务.我知道只有一种方法可以做到:
Trying to design something like ASP.NET, but need further understanding as to how to go about programming/designing it.
There would be a lot of unmanaged threads which needs to be served by a managed process (DLL). I know just one way to do this:
- 从非托管线程(使用COM接口)托管CLR
- 创建AppDomain并加载所需的程序集
- 调用托管程序集中的方法进行服务(此方法将更新包含将需要由非托管线程进行进一步处理的数据的数据结构)
- 卸载appdomain和clr
- host the CLR from the unmanaged thread (using COM interfaces)
- Create the AppDomain and load the required assembly
- Call the method in the managed assembly to do the serving (this method updates a data structure which contains data will need to get further processed by the unmanaged thread)
- unload the appdomain and clr
但是推荐这种方式吗?因为每次您创建CLR并将其销毁.我感觉那里一定有表现受到打击.
But is this way recommended? Because each time you are creating the CLR and destroying it. I sense there must be a performance hit there. Can we obviate this?
推荐答案
我们可以解决这个问题吗?
Can we obviate this?
使用C ++/CLI作为未管理代码到托管代码之间的接口.然后,无需创建CLR和AppDomain.
Use C++/CLI for the interface between unmanged-to-managed code. Then no need to create the CLR and AppDomain.
这篇关于如何通过托管进程服务非托管线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!