none
Questions about App Domains RRS feed

  • Question

  • I have two questions about App Domains:

    1. I need to create multiple instances of a legacy COM object. This COM object wraps an old MFC dll. The MFC dll uses global callback functions and global variables. If I load multiple instances of the COM object into separate app domains, can I be gaurenteed that the the global functions and variables will be unique across all the app domains? (Kinda like thread local storage?)

    2. I have a .net assembly that I load into a new app domain using AppDomain.CreateInstanceFromAndUnwrap. The object returns is a MarshalByRefObject. If I call a method on the object, will this method return when the code is finished execution in the new app domain (blocking call), or does it return right away (like posting a message to a queue)?

    Thanks for the help!

    Thursday, June 4, 2009 12:04 AM

Answers

  • 1) No.  Unmanaged code has no concept of AppDomains, it manages memory at the process level.
    2) It blocks.  Threads are allowed to cross an AppDomain boundary and will take their merry time executing code there, there is no special messaging at play.
    Hans Passant.
    • Marked as answer by daaboots Friday, June 5, 2009 12:03 PM
    Thursday, June 4, 2009 12:29 AM
    Moderator
  • AppDomains offer isolation only for code that is aware of their existence and that is managed code only. When you use unmanaged code the isolation boundary is given by the OS, not the CLR VM, and that boundary is the process. In other words when you instantiate a class, a COM component or allocate some memory in unmanaged code that operation is not managed by the CLR but by the OS directly.
    • Marked as answer by daaboots Friday, June 5, 2009 12:04 PM
    Thursday, June 4, 2009 2:01 PM

All replies

  • 1) No.  Unmanaged code has no concept of AppDomains, it manages memory at the process level.
    2) It blocks.  Threads are allowed to cross an AppDomain boundary and will take their merry time executing code there, there is no special messaging at play.
    Hans Passant.
    • Marked as answer by daaboots Friday, June 5, 2009 12:03 PM
    Thursday, June 4, 2009 12:29 AM
    Moderator
  • 1) No.  Unmanaged code has no concept of AppDomains, it manages memory at the process level.
    2) It blocks.  Threads are allowed to cross an AppDomain boundary and will take their merry time executing code there, there is no special messaging at play.
    Hans Passant.

    Hi nobugz.

    Can you point me to some documentation for question #1? The only documentation I could find about app domains is that they offer "similar" features as a separate process.

    Thanks a lot for the help!

    David
    • Marked as answer by daaboots Friday, June 5, 2009 12:03 PM
    • Unmarked as answer by daaboots Friday, June 5, 2009 12:04 PM
    Thursday, June 4, 2009 12:59 PM
  • AppDomains offer isolation only for code that is aware of their existence and that is managed code only. When you use unmanaged code the isolation boundary is given by the OS, not the CLR VM, and that boundary is the process. In other words when you instantiate a class, a COM component or allocate some memory in unmanaged code that operation is not managed by the CLR but by the OS directly.
    • Marked as answer by daaboots Friday, June 5, 2009 12:04 PM
    Thursday, June 4, 2009 2:01 PM