Re: Relationship between Application.Exit() and AppDomain



Hi Willi,

I agree that 'not in line with the docs' was, perhaps, an overstatement:).
What I actually wanted to say is that as far as I am concerned the
documentation was not clear about the scope of the Application object and the
relationship between Application, A.E method and AppDomains.

For example, you say ' ... you create a new application (Application.Run(..)
in each of the domains/threads ...' Define 'application'. Surely it's not a
new Application object or is it? BTW, the documentation just says that
calling A.R 'Begins running a standard application message loop on the
current thread'. I am not trying to be argumentative, I'm just trying to
understand what's going on.

Let's take one of your scenarios: "From AD1/thread1 you create another
thread, and you create a window and run a message pump in this thread." Why
can't I use the same logic as above and say that by 'creating a window and
running a message pump' on a new thread (through Application.Run(Form), I
presume) I create a new application?

Let's futher modify this scenario so that the second thread is created, as
above, from AD1/thread1, but in a separate AppDomain (AD2), so that AD2 is a
'child' of AD1. In this case, calling A.E on either of the threads doesn't
stop the other (I did test it:).

You see, this is the sort of questions I was trying to clarify for myself
and I found your comments quite helpful, thank you.

"Willy Denoyette [MVP]" wrote:

"Sunny S" <sunny.s@xxxxxxxxxxxxxxxx> wrote in message
news:67A7646B-4AA9-4B6E-89F6-A4C8CBE9B522@xxxxxxxxxxxxxxxx
Jon,

I’ve just done some more tests. My understanding of Willy Denoyette’s
explanation (see at the bottom of this thread) was that Application.Exit()
kills the message pumps in the current Appdomain and its ‘child’
AppDomains.

To verify this I further modified the code with AppDomains so that one of
the threads creates yet another ‘child’ AppDomain and starts yet another
message loop in it. This test showed that my understanding was incorrect.
All
three message loops in those AppDomains are independent in the sense that
killing one of them doesn’t kill the others.




I know this is quite confusing, but I'm not sure why you consider this "not
inline with the docs".
Note that the docs talks about applications, and stopping all message pumps
in the application, it doesn't talk about threads running other AD's.

In your last sample you are creating separate AD/thread pairs *and* you
create a new application (Application.Run(..) in each of the
domains/threads, calling A.E in one of the AD/threads only stops the
(single) message pumps in this application, which is inline with the docs,
right?

Now, say the from AD1/thread1 you create another thread, and you create a
window and run a message pump in this thread. That means, you have
AD1/thread1 and thread2, and two separate message pumps. Calling A.E from
one of these threads will stop all (2) pumps, which is inline with the docs,
right?

And, say you have a AD/thread that runs an application
(Application.Run(...)], and this thread creates another AD that shows a
form. Here you have two AD's, one *Application* and only one thread that
pumps the message queue of both the main form and the other AD's form. When
you call A.E from the second form code, you will simply unload the second AD
and it's form, but you won't stop the message pump. Calling A.E from the
main form will stop the message pump and close all forms tear down the AD's
for the whole application, which is again inline with the doc's.

Willy.



.



Relevant Pages

  • Re: Relationship between Application.Exit() and AppDomain
    ... calling A.E on T1 closes Form1, ... > relationship between Application, A.E method and AppDomains. ... It's the thread that must run a message pump in order to retrieve ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Relationship between Application.Exit() and AppDomain
    ... relationship between Application, A.E method and AppDomains. ... It's the thread that must run a message pump in order to retrieve Window messages from the application and from the System. ... calling A.E on either of the threads doesn't ... inline with the docs". ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Relationship between Application.Exit() and AppDomain
    ... calling A.R on a different thread in a separate AppDomain is ... It's the thread that must run a message pump in order to retrieve ... Window messages from the application and from the System. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: IMessageFilter and USER DEFINED MESSAGES
    ... This involves some GUI and it does have an internal ... In this situation multi threaded environment -multiple STA calling same ... Inside IMessageFilter::HandleInComingCall, I am getting ...
    (microsoft.public.vc.atl)