Click to See Complete Forum and Search --> : Using controls from other processes - primary window is hanging


Rennen.Chacham
March 6th, 2008, 02:18 PM
Hello,

-- Introduction --

I wish to "steal" a control from another process and use it in my window on my process, as if it was a part of my application.

The reason behind this is that the other process is not very stable and may crash\freeze suddently.

Hence, I have done the following:
1. After my process is fully created, I create the new processes from which I want to "steal" their windows.
2. I detect the window handle of the control I want to take over on.
3. Use SetParet() to move the other-process' control to be a child window.
Also, I'm setting the window size and location to match, and use ShowWindow on the original parent, to make the main window of the other process disappear.

When the application goes down, I kill the other process and the game is over.

-- The problem --

It is indeed made my software a lot more stable.
Whenever the other process crashes - my process is still alive.

Yet, sometimes the stolen control gets busy (i.e. responding to a button click, or due to some other freeze issue in the other process). When this occours, my process is hang as well, completely.

My desired behavior would be that the stolen control will be either grayed out or not painted, yet not to affect the main window and other controls. Maybe even change the title and add "Not responding" like windows is doing when a process hangs (and not just hangs the entire desktop).

Please help... how can I do it?

-- Things I've tried, without success --

I have tried running a thread to monitor the other process, and see if it is responding. However, the Process.Responding property in c# always consider both 2 processes as responding.

Also the other process' main gui thread is always at "waiting" mode, no matter what.

MikeAThon
March 6th, 2008, 03:47 PM
There's a general recommendation (from Microsoft and from many other reliable sources) against an architecture where the parent and child windows are created by different threads. It's complicated, and is related to message queues and message loops.

Your architecture is actually even more problematic, since you are creating parent and child in different processses (which don't share the same virtual memeory space) and not merely different threads in the same process.

I don't know how to resolve your problem. You might find some interesting leads with the AttachThreadInput() function: http://msdn2.microsoft.com/en-us/library/ms681956.aspx . AttachThreadInput() is one of the functions needed if you have parent and child created in different threads, and you want it to work. Google for it in the context of the problems you are encountering.

Mike

Rennen.Chacham
March 7th, 2008, 02:43 PM
Thanks for the quick answer.

I don't see how AttachThreadInput() can actually resolve my issue.
It might help me refactoring it and doing it "the proper way", though.

Yet, I need somehow a mechanism to detect that a certain control is hang and cut it loose from the window messaging mechanism and continue handling other messages - until it's available again.

However, I don't really know how to detect that, since all processes seem to be responding.

Any other ideas?