0

为什么在运行此控制台应用程序时会收到 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
{

}

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

4

1 回答 1

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));
        }
    }
于 2015-09-06T13:48:49.387 回答