Using SetParent to steal the main window of another process, but saving separate message loops

Reference Information. My colleague and I support the application we inherited with millions of lines. Its interface is written in VB6, and since we devote almost all our resources to converting it to C #, we are looking for quick and dirty solutions to our specific problem.

The application behaves like a plugin. Up to 20 separate ActiveX controls are available that can be loaded right away in a grid layout. The problem is that ActiveX controls do all of their processing in their user interface thread, and since many of them block waiting for network access, the user interface becomes very nice. When our C # hosting application loads these controls, it becomes unresponsive due to how many controls chew on UI resources without doing anything. To cope with this, the controls are fragile and will collapse at the slightest provocation. When they are hosted in the main C # application, this creates serious instability.

My best colleague I came with is running the process on an ActiveX control. This process, which we call proxies, is another winforms application. It uses named pipes to communicate with the hosting process. The hosting process creates a window, loads the ActiveX control of our choice (through some reflections and AxHost magic) and tells the main process that its window handle is through the named pipe. The main process uses a combination of SetParent and SetWindowPos to move the proxy application into itself to emulate the plugin. Size updates are sent through the named pipe.

This works quite well until the ActiveX application runs some lengthy process, and we click on the main window while we work. For a while, the main window responds, but in the end it stops responding because the child window expects its user interface thread. How can we keep child windows in their own full flow while preserving the benefits of SetParent?

(please let me know if something is not clear!)

+3
source share
1 answer

I have done this before. It is getting dirty.

AppDomain, . , , .

, AppDomains, . , Application.Run AppDomain/plugin. - .

:)

+5

Source: https://habr.com/ru/post/1796227/


All Articles