简体   繁体   中英

how to know if 2 projects are at the same appdomain

I created 5 projects in the same solution assuming they all have the same app domain so they all can share static variables (as it's static per appdomain) so how do i make sure they are all on the same appdomain ? if they aren't how to make them all run at the same app domain. also how could i give them the same namespace and they all still have their own namespaces ?

for instance project1 namespace is Bigproject.project1 , project2 namespace is Bigproject.project2 and so on ?

(i've had troubles trying to do that with a winf. app)

it's not one project with libraries, it's 2 console applications with 1 win form and 2 libraries, problem is one of the console form takes different instance from that library than the instance of the win form where by instance i refer to instance of static variable, thus i suspected that im not running on the same appdomain

AppDomains are specific to a process. Just run them inside the same process.

A process can have multiple AppDomains. If you are creating AppDomains or running these assemblies in different processes, then you will manually have do manage the communication between them.

I created 5 projects in the same solution assuming they all have the same app domain so they all can share static variables

If your solution has a single executable that references the other libraries I think that's a reasonable assumption.

how do i make sure they are all on the same app domain ?

The app domain will be determined by the assembly that they're referenced from. You can't "ensure" that two libraries will be loaded into the same app domain - it's entirely plausible for two separate applications to reference the libraries in separate app domains.

That said, if the libraries are referenced by the same executable then they will be in the same app domain (you have to explicitly load assemblies into a separate app domain)

it's not one project with libraries, it's 2 console applications with 1 win form and 2 libraries

Then you need to use some sore of inter-process communication (web service, WCF), or a central repository (database).

Projects are not synonymous with AppDomains, unless you are specifically creating a new app domain then all the objects you reference in your application are most likely in the same app domain via their entry point mechanism. That mechanism could be an .exe or a web request under ASP.NET etc..

The common exceptions to this would be:

  • When you are communicating via WCF or .NET Remoting (RPC, IPC)
  • Communicating over any SOA transport like HTTP etc...

As for symptoms of communicating from one app domain to another you would see your call stacks having proxies in them, see MarshalByRefObject and ContextBoundObject

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM