问题
Why do a get a DeathWatchNotification when running this console app:
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
{
}
Obviously I haven't sent any messages and the actor doesn't do anything. It's not a huge deal but I'm concerned I'll miss a real problem if I ignore this message.
回答1:
As I understand, DeathWatchNotification is a special type of message, that actor sends to its watcher(s) when it's getting terminated. For example, consider this piece of code, that I got from the source of Akka.NET-1.0.4 (ActorCell.DeatWatch.cs file):
private void SendTerminated(bool ifLocal, IActorRef watcher)
{
if (((IActorRefScope)watcher).IsLocal == ifLocal && !watcher.Equals(Parent))
{
watcher.Tell(new DeathWatchNotification(Self, true, false));
}
}
来源:https://stackoverflow.com/questions/32386573/why-do-i-get-a-deathwatchnotification-of-an-undelivered-message-on-shutdown