Re: Relationship between Application.Exit() and AppDomain

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Sunny S" <sunny.s@xxxxxxxxxxxxxxxx> wrote in message news:DB96CD9F-4274-4ED9-9028-D0ECBB323A36@xxxxxxxxxxxxxxxx
Keep hitting wrong buttons, sorry...

Gentlemen, thank you very much for an interesting discussion, from which I
learned a lot, but I feel I had to be more specific.

1. Let’s say I’ve started a SimpleWinForm application. I presume that means
starting a message loop.

2. From within that application I create an AppDomain in which I create a
new thread on which I call Application.Run(new SomeOtherWinForm()). See, for
example, Jon Skeet’s code above except that the code should be running on a
dedicated thread in a separate AppDomain.

Microsoft documentation says that Application.Exit() method ‘Informs ALL
message pumps that they must terminate, and then closes all application
windows after the messages have been processed’.

From the above I would conclude that upon calling Application.Exit() both
SomeOtherWinForm and SimpleWinForm should close and the whole thing should
terminate. Experiments show that this is not the case – only SomeOtherWinForm
closes.

Again, Microsoft documentation for System.Windows.Application (not
System.Windows.Forms.Application!) says that there is only one instance of
Application object per AppDomain. It looks as if the same relationship is
true for System.Windows.Forms.Application objects and AppDomains, because
this would explain the above behaviour, but I wasn’t sure.

SS

When the documentation says "all running message loops on all threads and closes all windows of the application." it really should say in the callers AppDomain (AD) and it's owning AD's.
That means, that if you call Application.Exit in a child AD , only the child AD windows will be affected. If, however you cal A.E from the parent AD , then also the child AD windows will be affected.
Note also that Windows.Forms was not designed to be run from within multiple domains in a single process.


Willy.




.


Quantcast