为什么我在关机时获得未传递消息的DeathWatchNotification?

时间:2015-09-03 22:44:25

标签: akka.net

为什么在运行此控制台应用程序时获取DeathWatchNotification:

class Program
{
    private static ActorSystem TestSystem; 

    static void Main(string[] args)
    {
        TestSystem = ActorSystem.Create("TestSystem");
        TestSystem.ActorOf<TestActor>("Test");

        Console.WriteLine("Press a key to shutdown actor system");

        Console.ReadKey();
        TestSystem.Shutdown();
        TestSystem.AwaitTermination();

        Console.WriteLine("Press a key to quit");

        Console.ReadKey(); 
    }
}

public class TestActor : ReceiveActor
{
    public TestActor()
    {

    }
    protected override void Unhandled(object message)
    {
        Console.WriteLine("unhandled message");
        //Do something with the message.
    }

}

public class TestMessage
{

}

显然我没有发过任何消息而且演员没有做任何事情。这不是一个大问题,但我担心如果我忽略这个消息,我会错过一个真正的问题。

1 个答案:

答案 0 :(得分:0)

据我所知,DeathWatchNotification是一种特殊类型的消息,当演员被终止时,该演员会向其观察者发送消息。 例如,考虑一下这段代码,我是从Akka.NET-1.0.4(ActorCell.DeatWatch.cs文件)的源代码中获得的:

    private void SendTerminated(bool ifLocal, IActorRef watcher)
    {
        if (((IActorRefScope)watcher).IsLocal == ifLocal && !watcher.Equals(Parent))
        {
            watcher.Tell(new DeathWatchNotification(Self, true, false));
        }
    }
相关问题