T
Tony Johansson
Hi!
Here I have a console program that is creating 5 app domain running an exe
in each one.
Now assume that I want to run 5 exe files called Foo.exe.
If I instead only created one app domain and started 5 threads running the
Foo.exe in each thread which solution od these two would be the best choice
?
I would say that using 5 app domain running an exe in each would be th ebest
solution.
Do you agree with me ?
using System;
using System.Threading;
public class MyApp
{
private int sleepTime = 1000;
private AppDomain appDom;
private Thread appThrd;
private AppDomainSetup appSetup;
public MyApp(string domain, string process) //create 5 AppDomain domain
in the C-tor
{
appSetup = new AppDomainSetup();
appSetup.ApplicationName = process;
appSetup.ApplicationBase = "file:///" +
System.Environment.CurrentDirectory;
appDom = AppDomain.CreateDomain(appSetup.ApplicationName + " - " +
domain, null, appSetup);
}
public void Run()
{
appThrd = new Thread(new ThreadStart(this.RunApp));
appThrd.Start();
}
private void RunApp()
{
string[] args = new string[] { sleepTime.ToString() };
appDom.ExecuteAssembly(appSetup.ApplicationName);
Console.WriteLine(appSetup.ApplicationName + " started.");
}
}
public class Program
{
static void Main(string[] args)
{
MyApp[] apps = new MyApp[5];
string appName = "Foo.exe";
for (int i = 0; i < 5; i++)
{
apps = new MyApp(("Application" + (i + 1)), appName);
apps.Run();
}
}
}
//Tony
Here I have a console program that is creating 5 app domain running an exe
in each one.
Now assume that I want to run 5 exe files called Foo.exe.
If I instead only created one app domain and started 5 threads running the
Foo.exe in each thread which solution od these two would be the best choice
?
I would say that using 5 app domain running an exe in each would be th ebest
solution.
Do you agree with me ?
using System;
using System.Threading;
public class MyApp
{
private int sleepTime = 1000;
private AppDomain appDom;
private Thread appThrd;
private AppDomainSetup appSetup;
public MyApp(string domain, string process) //create 5 AppDomain domain
in the C-tor
{
appSetup = new AppDomainSetup();
appSetup.ApplicationName = process;
appSetup.ApplicationBase = "file:///" +
System.Environment.CurrentDirectory;
appDom = AppDomain.CreateDomain(appSetup.ApplicationName + " - " +
domain, null, appSetup);
}
public void Run()
{
appThrd = new Thread(new ThreadStart(this.RunApp));
appThrd.Start();
}
private void RunApp()
{
string[] args = new string[] { sleepTime.ToString() };
appDom.ExecuteAssembly(appSetup.ApplicationName);
Console.WriteLine(appSetup.ApplicationName + " started.");
}
}
public class Program
{
static void Main(string[] args)
{
MyApp[] apps = new MyApp[5];
string appName = "Foo.exe";
for (int i = 0; i < 5; i++)
{
apps = new MyApp(("Application" + (i + 1)), appName);
apps.Run();
}
}
}
//Tony