编程语言
首页 > 编程语言> > C#-Apache Ignite.NET和AppDomain.CurrentDomain.ProcessExit

C#-Apache Ignite.NET和AppDomain.CurrentDomain.ProcessExit

作者:互联网

考虑使用Apache Ignite.NET库的类

public interface ICluster
{
    void Join();

    void Leave();
}

public class ApacheIgniteClusterImpl : ICluster
{
    private IIgnite Ignite { get; set; }

    private int MulticastPort { get; }

    private int ThinClientPort { get; }

    public ApacheIgniteClusterImpl(int multicastPort = 47401, int thinClientPort = 10800)
    {
        MulticastPort = multicastPort;
        ThinClientPort = thinClientPort;
    }

    public void Join()
    {
        if (Ignite != null)
        {
            return;
        }

        var configuration = new IgniteConfiguration
        {
            ClientConnectorConfiguration = new ClientConnectorConfiguration
            {
                Port = ThinClientPort,
            },
            DiscoverySpi = new TcpDiscoverySpi
            {
                IpFinder = new TcpDiscoveryMulticastIpFinder()
                {
                    MulticastPort = MulticastPort,
                }
            },
            JvmOptions = new List<string>()
            {
                "-DIGNITE_NO_SHUTDOWN_HOOK=true",
            },
        };

        // Start
        Ignite = Ignition.Start(configuration);
    }

    public void Leave()
    {
        Ignition.Stop(null, true);
        Ignite = null;
    }
}

通常,在.NET Standard中,允许我们挂接到AppDomain.CurrentDomain.ProcessExit事件中,以执行清理工作.但是,一旦由Apache Ignite.NET创建JVM,当我使用kill< pid>杀死MacOS上的控制台应用程序时,将永远不会触发AppDomain.CurrentDomain.ProcessExit.

我在调试时做了一些研究,发现它将在调用私有静态Jvm CreateJvm(IgniteConfiguration cfg,ILogger log)之后的某个地方发生.

知道那里发生了什么吗?是否有可能我们可以加入AppDomain.CurrentDomain.ProcessExit?

UPD:AppDomain.CurrentDomain.DomainUnload或System.Runtime.Loader.AssemblyLoadContext.Unloading都不起作用.

解决方法:

ProcessExit is not guaranteed to be called.

我相信Ignite.NET与此无关.我已经检查了这一点(没有引用或启动Ignite),并且如果强行终止该过程,则不会调用该处理程序.

标签:net-core,ignite,c,net
来源: https://codeday.me/bug/20191108/2009053.html