2
1つのアプリケーションドメインの例外が別のアプリケーションドメインに影響するのはなぜですか?子ドメインクローズプログラムで例外が発生するのはなぜですか?
プログラムの終了を防止するにはどうすればよいですか?
using System;
using System.Reflection;
using System.Threading;
namespace domain
{
public class Worker : MarshalByRefObject
{
public static void NotMyCodeThreadProc()
{
throw new Exception();
}
public void NotMyCode()
{
var thread = new Thread(NotMyCodeThreadProc);
thread.Start();
thread.Join();
}
}
class Program
{
static void Main()
{
AppDomain ad = AppDomain.CreateDomain("New domain");
Worker remoteWorker = (Worker) ad.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "domain.Worker");
try
{
remoteWorker.NotMyCode();
}
catch
{
}
Console.WriteLine("!");
Console.ReadLine();
}
}
}
未処理例外ポリシーを変更するには、カスタムCLRホストが必要です。 C#のコードで書くことはできません。 Google ICLRPolicyManager :: SetDefaultAction() –