Application Domain

T

Tony Johansson

Hi!

I'm reading about Application Domain and trying to understand how it works.
This example below is not from the book but only a test from me to see what
would happened.
Here I have tried to start notepad from an Application Domain that I have
created but I get an Exception. A translation from native language to
english is
"BadImageFormatExcption was unhandled
It's not possible to read in the file after assembly
file:///C\WINDOWS\notepad.exe or one of its dependencis. The module expected
contain an assemblymanifest"

static void Main(string[] args)
{
AppDomain d = AppDomain.CreateDomain("newDomain");

Console.WriteLine("Host domain: " +
AppDomain.CurrentDomain.FriendlyName);
d.ExecuteAssembly(@"C:\WINDOWS\notepad.exe");
}

//Tony
 
F

Family Tree Mike

Hi!

I'm reading about Application Domain and trying to understand how it works.
This example below is not from the book but only a test from me to see what
would happened.
Here I have tried to start notepad from an Application Domain that I have
created but I get an Exception. A translation from native language to
english is
"BadImageFormatExcption was unhandled
It's not possible to read in the file after assembly
file:///C\WINDOWS\notepad.exe or one of its dependencis. The module expected
contain an assemblymanifest"

static void Main(string[] args)
{
AppDomain d = AppDomain.CreateDomain("newDomain");

Console.WriteLine("Host domain: " +
AppDomain.CurrentDomain.FriendlyName);
d.ExecuteAssembly(@"C:\WINDOWS\notepad.exe");
}

//Tony

Tony,

Notepad.Exe is not a .Net assembly. The method you are calling is
intended to run a .Net assembly only. The MSDN docs describe the
exceptions that can be thrown by the method, and the possible reasons
for each exception.

http://msdn.microsoft.com/en-us/library/sxx9f4c2.aspx
 
T

Tony Johansson

Hi!

The assembly where this Main is located in is called AppDomainDemo.
This process AppDomainDemo is creating the new Application Domain called
"New Domain" and then start the assembly that is reference by "ShowBootIni".
All this works good.
If I start the same assembly in this way instead
System.Diagnostics.Process.Start(@"F:\C#\AppDomainTest\Lesson1-ShowBootIni-CS\ShowBootIni\ShowBootIni\bin\Debug\ShowBootIni.exe");
then I can easily stop the process from task manager
but when I use the Application Domain I don't have that possibility to do
so.

So how can I stop the assembly(process) that has been started in an
Application Domain ?

static void Main(string[] args)
{
AppDomain myAppDomain = AppDomain.CreateDomain("New Domain");
myAppDomain.ExecuteAssemblyByName("ShowBootIni");
}

//Tony
 
A

Arne Vajhøj

The assembly where this Main is located in is called AppDomainDemo.
This process AppDomainDemo is creating the new Application Domain called
"New Domain" and then start the assembly that is reference by "ShowBootIni".
All this works good.
If I start the same assembly in this way instead
System.Diagnostics.Process.Start(@"F:\C#\AppDomainTest\Lesson1-ShowBootIni-CS\ShowBootIni\ShowBootIni\bin\Debug\ShowBootIni.exe");
then I can easily stop the process from task manager
but when I use the Application Domain I don't have that possibility to do
so.

So how can I stop the assembly(process) that has been started in an
Application Domain ?

static void Main(string[] args)
{
AppDomain myAppDomain = AppDomain.CreateDomain("New Domain");
myAppDomain.ExecuteAssemblyByName("ShowBootIni");
}

ExecuteAssemblyByName does not start a process - it does not
even start a thread.

So you need to just stop your app.

In case you would want to stop it programmatically then use:
myAppDomain.Unload()

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top