// Create an (immutable) message type that your actor will respond to publicclassGreet { publicGreet(string who) { Who = who; } publicstring Who { get;privateset; } }
// Create a new actor system (a container for your actors) var system = ActorSystem.Create("MySystem");
// Create your actor and get a reference to it. // This will be an "IActorRef", which is not a reference to the actual actor // instance but rather a client or proxy to it. var greeter = system.ActorOf<GreetingActor>("greeter");
// Send a message to the actor. greeter.Tell(new Greet("World"));
// This prevents the app from exiting // before the async work is done. Console.ReadLine();
// Create an (immutable) message type that your actor will respond to typeGreet= Greet ofstring
let system = ActorSystem.Create "MySystem"
// Use F# computation expression with tail-recursive loop // to create an actor message handler and return a reference let greeter = spawn system "greeter"<|fun mailbox -> letrec loop() =actor { let! msg = mailbox.Receive() match msg with | Greet who ->printf"Hello, %s!\n" who return! loop() } loop()