Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
I got confused about the description of AppDomain in MSDN.[^]

It's said:
Faults in one application cannot affect other applications. Because type-safe code cannot cause memory faults, using application domains ensures that code running in one domain cannot affect other applications in the process.

But any unhandled exception in any thread, no matter which AppDomain the code runs in, will cause the entire process crash. So how to understand the reliability provided by AppDomain?
Posted
Comments
[no name] 3-Aug-12 15:45pm    
The answer to your question is right there in your statement, "Faults in one application cannot affect other applications"
xTerryx 3-Aug-12 16:06pm    
but if there is any unhandled exception, no matter which AppDomain the exception is thrown, will cause the entire process crash. So does it have conflicts with "Faults in one application cannot affect other applications"?
[no name] 3-Aug-12 16:10pm    
What does that have to do with anything? So your app crashes. It's not going to affect other applications.
xTerryx 3-Aug-12 16:17pm    
I mean, there are multiple AppDomains, a unhandled excepion happens in one AppDomain, other AppDomains will also crash. so it's not reliable, righ?
[no name] 3-Aug-12 16:18pm    
No. Where do you get that? Thread != App domain

1 solution

You main problem is that you are using inadequate notion of "crash".

In essence, having unhandled exception in an application is strictly equivalent to exit from the entry point method, if you think about it. You have some exception propagation along the stack of some thread. When the instruction flow jumps to the top of the stack with exception mechanism, and top-level try-catch block was not used, the application has nothing to do but terminate the thread. If it was the only thread in the process, the process terminates. But even termination of the process does not always happen, because it can be some other thread, not the one of the entry point.

Now, Application Domain does not change this picture much. Actually, Application Domains can share threads and hence, the stacks of them. So, you can make a call in one Application Domain under try-catch, have an exception thrown in another Application Domain, not handled (which is actually good). In this case, the exception will propagate back to the calling Application Domain. And, optionally, caught there.

This does not reduce reliability even a bit, but, if exception is properly handled on top of stack of each thread (no matter which Application Domain), can greatly improve it.

—SA
 
Share this answer
 
Comments
xTerryx 3-Aug-12 21:03pm    
ok. understand what you mean. If the reliability provided AppDomain isolation is all about isolation of memory and code, what does "Faults in one application cannot affect other applications" mean? I don't quiet understand. Does it mean "Faults" -> "Exception"? and "application" -> "AppDomain"?
Sergey Alexandrovich Kryukov 4-Aug-12 0:54am    
Fault and exception are different things. And exception is not an error. A big topic to discuss... I explained how exception works with Application Domains. Now, the isolation. The isolation is in the address spaces (it includes handles as well, such as thread handle, and unmanaged handles, and unmanaged memory). You can do something fatal to the memory. Exception or not -- does not matter. You can have memory leak, you can have a complex chain in allocation and an exception in the middle, so the memory becomes half-allocated in some uncertain phase; it's especially typical for unmanaged memory. You can make Application Domain unusable. You can unload it all and load again. Nothing touches other Application Domains.
--SA
xTerryx 4-Aug-12 11:00am    
so memory leak is some kind of fault, right? And memory leak in app domain does not affect another?
Sergey Alexandrovich Kryukov 5-Aug-12 17:10pm    
Why addressing particular issues when they are covered by more general fact? Address spaces are totally isolated. Not only it does not affect another domain; the concept is the leak, as anything else related to memory, is related to one Application Domain in principle.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900