Akka.NET Ask Task never completes

I might be doing something wrong, but it's not obvious. I have the following code:

 namespace test
    {
        class Program
            {
             static void Main(string[] args)

                {
                    using (var system = ActorSystem.Create("MySystem"))
                    {
                        var testPassRetriever = system.ActorOf<PrintActor>();
                        var task = testPassRetriever.Ask<PrintActorMsg>(new PrintActorMsg());

                        // prevent the application from exiting before message is handled
                        task.Wait();
                        Console.WriteLine("Finished.");
                        Console.ReadLine();
                    }
                }
        }
        class PrintActorMsg{}

        class PrintActor : ReceiveActor
        {
            public PrintActor()
            {
             Receive<PrintActorMsg>(msg => Console.WriteLine("foo"));
            }
        }
}// namespace test

      

The problem is that the task returned by Ask never completes. Its status remains in the Waiting for activation state. "Foo" is indeed printed on the command line, so I know the actor is handling the "Print" message. Is there something else I have to do in the overridden PrintMsg role to mark the completed task?

+3


source to share


1 answer


You are using a request template, but you never send a message. The request task will be executed only after receiving the message from the actor. (Sometimes advises) to say, or shoot and forget the pattern does not.



+6


source







All Articles