T
Tony Johansson
Hello!
Here is a program that is using Application Domain but it doesn't work as
expected.
Method SomeMethod() is executing in a separate thead in a separate
application Domain.that is called SecondDomain.
In this method SomeMethod() I divide by zero on purpose so I expect that
this domain should stop and the main thread should continue with the for
loop.
What happens now is that I get an exception which is correct about division
by with zero and then the whole application stop.
So the main thread doesn't continue with the for loop.
My purpose of this test was to check that the main thread in the primary
application domain could continue executing when
the new application domain with it's own additional thread run into problem
such as divide by zero.
using System;
using System.Text;
using System.Threading;
public class Program
{
static void Main(string[] args)
{
AppDomain domain = AppDomain.CreateDomain("SecondDomain");
Thread.CurrentThread.Name = "Thread 2";
//// Thread.Start in first domain
Thread thread = new Thread(SomeMethod);
thread.Name = "Thread 1";
thread.Start();
//// Current thread, for simpliicty, second domain
////The CrossAppDomainDelegate is a good tool for threading across
appdomain
////boundaries.
domain.DoCallBack(new CrossAppDomainDelegate(SomeMethod));
for (int i = 0; i < 10; i++)
{
Console.WriteLine("In main Thread=" + i);
Thread.Sleep(1000);
}
Console.ReadLine();
}
static void SomeMethod()
{
int tal = 10;
int sum = 10;
Console.WriteLine("Domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("Thread: " +
System.Threading.Thread.CurrentThread.Name);
Thread.Sleep(2000);
tal = 0;
sum = sum / tal;
}
}
//Tony
Here is a program that is using Application Domain but it doesn't work as
expected.
Method SomeMethod() is executing in a separate thead in a separate
application Domain.that is called SecondDomain.
In this method SomeMethod() I divide by zero on purpose so I expect that
this domain should stop and the main thread should continue with the for
loop.
What happens now is that I get an exception which is correct about division
by with zero and then the whole application stop.
So the main thread doesn't continue with the for loop.
My purpose of this test was to check that the main thread in the primary
application domain could continue executing when
the new application domain with it's own additional thread run into problem
such as divide by zero.
using System;
using System.Text;
using System.Threading;
public class Program
{
static void Main(string[] args)
{
AppDomain domain = AppDomain.CreateDomain("SecondDomain");
Thread.CurrentThread.Name = "Thread 2";
//// Thread.Start in first domain
Thread thread = new Thread(SomeMethod);
thread.Name = "Thread 1";
thread.Start();
//// Current thread, for simpliicty, second domain
////The CrossAppDomainDelegate is a good tool for threading across
appdomain
////boundaries.
domain.DoCallBack(new CrossAppDomainDelegate(SomeMethod));
for (int i = 0; i < 10; i++)
{
Console.WriteLine("In main Thread=" + i);
Thread.Sleep(1000);
}
Console.ReadLine();
}
static void SomeMethod()
{
int tal = 10;
int sum = 10;
Console.WriteLine("Domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("Thread: " +
System.Threading.Thread.CurrentThread.Name);
Thread.Sleep(2000);
tal = 0;
sum = sum / tal;
}
}
//Tony