WinForms and AppDomains

G

Guest

I have an application where I'd like to be able to run multiple instances of
a Windows forms application. Due to a heavy hit in our application startup
code it would be beneficial to be able to have a single process with multiple
instances of the form. Additionally, it would be useful to be able to
partition off each instance in it's own application domain. The current plan
is for a module to handle starting a new thread which will fire up a new app
domain and then load the form. This module will also handle firing up any new
instances by creating a new thread and application domain.

My concern is any issues surrounding the UI thread. I'm aware that only the
thread that calls Application.Run should access any of the UI components.
Typically you would only have one per process. In my situation I'll end up
with multiple UI threads. However, each application domain will only have a
single UI thread and only this thread will access any UI components.

Is the application domain enough of a boundary for the UI threads or am I
setting myself up for threading issues?
 
R

Richard Grimes [MVP]

Jeremy said:
My concern is any issues surrounding the UI thread. I'm aware that
only the thread that calls Application.Run should access any of the
UI components. Typically you would only have one per process. In my

Why only have one per process? If you have multiple appdomains then you
have in effect multiple 'light weight processes', there's nothing to say
that each of these cannot have its own message pump.
situation I'll end up with multiple UI threads. However, each
application domain will only have a single UI thread and only this
thread will access any UI components.

Sounds OK to me.
Is the application domain enough of a boundary for the UI threads or
am I setting myself up for threading issues?

I don't think so. The only issue is that Application.Run sets up the
interaction between the UI thread and office through IMsoComponent. I do
not know if multiple 'MsoComponent's in a process has any issues,
however, the way that they are stored in thread context indicate to me
that you are allowed to have more than one in every process.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top