views:

682

answers:

3

Google Chrome and IE8 (among others) aim to provide greater reliability/stability by isolating each tab (web page) in a separate process (over-simplified, I know).

This would seem to be much more heavyweight then multiple threads, but has the major benefit of a crash in one process not bringing down the whole application.

It seems the multiple process architecture has long been used in server side applications (eg. web servers), but these are processes without a dedicated GUI. It's interesting that it is now being employed in the user interfaces of desktop applications.

How would I go about implementing this in say a Windows Forms .NET application? Is it even possible?

Process.Start() is an obvious first place to look, but the GUI of the new process is not tightly integrated with the GUI of the host application. It's a new standalone application, not a sub control/window of the host application, as it is with Chrome/IE8.

(For anyone interested Scott Hanselmann wrote a good intro. to the IE8 multi-process architecture here.)

[Update]

More specifically:

How can a separate "sub-process" render directly to the UI within the "main process"? Is this actually what is happening, or as was suggested in comments, does the sub-process use IPC to ask the main process to render for it?

+2  A: 

A better option to using multiple processes in .NET would be to use multiple AppDomains instead. This has the advantage of only creating one actual Windows process, yet still giving the added stability of multiple areas (i.e. a crash in one AppDomain would only take that one down, not the whole app).

There are costs associated with this, since objects need to be serialized across AppDomain-boundaries. It might be easier to develop than a multi-process model, though.

Andy
+1, especially the caveats of communicating between domains. That can be much more costly than developers sometimes expect.
Rex M
Can 2 AppDomains in a single process update the user interface independently, ie separate tabs? Also, as Scott Hanselmann says, it is still possible to bring down the whole process from one AppDomain.
Ash
@Ash assuming one process/AppDomain is the "GUI" process, responsible for receiving commands from other processes and reflecting them; and eventing back to them, why not?
Rex M
@Rex, so do you thnk that is roughly how Chrome/IE8 would do it?
Ash
@Ash I can only speculate how they do it, but that's the most reasonable way I can think of. How else would the GUI not go down with a tab? There has to be a master process to coordinate everything and spawn new ones.
Rex M
@Ash I'm not sure about WPF, but with WinForms you need to be in the same AppDomain in order to interact with the GUI controls. I'd guess that WPF is the same way, but I haven't checked it myself.
Andy
WPF has some trickery for this: http://stackoverflow.com/questions/197182/winforms-app-like-google-chrome-with-multiple-processes/197264#197264
Kalmi
+2  A: 

Google Chrome is using named pipes for inter-process communication.

There are some interesting documents here: http://dev.chromium.org/developers/design-documents

For more information on named pipes with ".net" just google it.

@Ash: The child processes are running in separate Windows "Desktops" which means that they have no way of displaying anything. (Desktops are a tricky thing...) So I must assume that everything the child processes renders must go through IPC. And then the main(?) process displays it.

I found that separate Windows "Desktop" thing here: http://dev.chromium.org/developers/design-documents/multi-process-architecture

(I was going back to editing too fast and failed human verification and got sent to some Robot Song on youtube :D)

Kalmi
Any idea on how it implements the GUI interaction side?
Ash
Excellent links on Chrome, thanks,
Ash
You are welcome. I'm also very interested in this. :)
Kalmi
And here is some (hard to find) info on Desktops: http://msdn.microsoft.com/en-us/library/ms682573(VS.85).aspx ( I mentioned it and it's not a well-known thing, so I thought I would share.)
Kalmi
+1  A: 

btw... dup

See: http://stackoverflow.com/questions/197182/winforms-app-like-google-chrome-with-multiple-processes (with answer from Jon Skeet :o )

(I think this answers the "more specifically" part too)

Kalmi
Thanks again. I did spent 5 minutes searching for an existing question. I also typed various titles into the "Ask Question" textbox. These don't work very well in my experience, oh well.
Ash
I just had a quick glance at the "Related" box on the right :P
Kalmi