Skip to content

Instantly share code, notes, and snippets.

@ralfw
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfw/8b5e796f5012f549b170 to your computer and use it in GitHub Desktop.
Save ralfw/8b5e796f5012f549b170 to your computer and use it in GitHub Desktop.
Akka Question
using System;
using System.Windows.Forms;
using Akka.Actor;
namespace spike.akka
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var sys = ActorSystem.Create("MyActorSystem");
var bodyActorProps = Props.Create<BodyActor>();
var bodyActor = sys.ActorOf(bodyActorProps, "BodyActor");
var dlg = new Form1();
var headActorProps = Props.Create<HeadActor>(dlg, bodyActor)
.WithDispatcher("akka.actor.synchronized-dispatcher");
var headActor = sys.ActorOf(headActorProps, "HeadActor");
Application.Run(dlg);
}
}
internal class HeadActor : ReceiveActor
{
public HeadActor(Form1 dlg, IActorRef onDataEntered)
{
dlg.OnDataEntered += msg => {
Console.WriteLine("head {0}", System.Threading.Thread.CurrentThread.GetHashCode());
onDataEntered.Tell(msg);
};
// Why aren't any messages received here from BodyActor?
Receive<string>(msg => {
dlg.Display_message(msg);
});
}
}
internal class BodyActor : ReceiveActor
{
public BodyActor()
{
Receive<string>(msg =>
{
Console.WriteLine("body {0}", System.Threading.Thread.CurrentThread.GetHashCode());
this.Sender.Tell(msg.ToUpper());
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment