views:

1057

answers:

3

Both IE8 and Google Chrome browser have separate processes for each tab that is opened.

For example, you launch IE8 and open Yahoo and Google in their own tabs, you end up with 3 processes running on your system:

  • IE8 itself process [master process]
    • Google tab process
    • Yahoo tab process

I'm toying with the idea of a similar thing in C#/WinForms.

Take a simple example: I have a master process that shows a Form, and I have a Button in a child process. How can we render the Button from the other process onto my Form?

A: 

That doesn't sound like such a good idea. The winforms common controls are for the most part not thread-safe, and giving each control it's own process seems icky.

If you want to try this, perhaps give each form it's own process, or even just it's own thread. Or perhaps if you have a tab control then just give each tab its own thread.

Update
.Net provides something called an AppDomain that you can use. It's more than a thread, but less than a process. If you have a from with multiple tab pages, you could create a custom control that holds the contents for each tab page and put each custom control in it's own assembly. Then those assemblies can be dynamically loaded into their own AppDomains. From there you should be able to create an instance of the control you want. However, there are certain rules about talking across appdomains, so I don't know that you'd be able to just add that control to a tab page on your form.

Joel Coehoorn
Joel, thanks for the answer. 1 thread per tab won't work, it defeats the purpose of sandboxing each tab in its own process, preventing it from crashing or freezing the parent process. See Ryan's answer about sandboxing.
Judah Himango
A: 

The reason that chrome gives each tab its own process is sandboxing. If one tab behaves errantly it is less likely to take down the whole browser. Is there a similar need in your app?

Also, note that browser tabs don't need to share information. What's on a tab is on a tab and no other tab needs to care about it. Is your winforms app similarly divided?

Ryan
Thanks for the answer. I understand the valid reasoning behind sandboxing. My app is similarly divided, with tabs that don't need to know about each other, and all shouldn't be able to crash the parent process.
Judah Himango
A: 

This question is a duplicate. See here.

smink
Thanks. SO didn't show me that question as I had typed the subject to this question. Oh well.
Judah Himango