Tim Coker
Tim Coker

Reputation: 6524

Implications in calling a .Net exe's main() function

In .net, exes are assemblies and can be referenced just like dlls. This means that any of their types can be used from any other program given they're defined as public. What are the implications in calling another exe's Main function from your code? Obviously the thread that Main is called in would be blocked until the program terminated, unlike spawning a new process. What other potential issues would this have?

Upvotes: 4

Views: 277

Answers (2)

Tim Coker
Tim Coker

Reputation: 6524

I looked up the specifics about AppDomains in Jeffery Richter's CLR via C#. Here are the bullet points he gives about what AppDomains provide for those who are curious about the things that would be corruptible/open security holes.

  • Objects created by code in one AppDomain cannot be accessed directly by code in another AppDomain

  • AppDomains can be unloaded

  • AppDomains can be individually secured

  • AppDomains can be individually configured

Upvotes: 0

SLaks
SLaks

Reputation: 888185

The program would run in your AppDomain.

Therefore, any shared state used by both programs could get messed up.

To solve this, you can call AppDomain.ExecuteAssembly.

In either case, the program itself might not handle it correctly - the current directory, command-line arguments, and other per-process state (such as environment variables) would be shared with the parent process.

Upvotes: 5

Related Questions