Recently learned some of the C # dataflow some things, and then a person abroad, with dataflow to achieve, an Actor model;
Here is a comparison, is the first knowledge of our actor model, and then we further in-depth understanding of a ha;
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Threading.Tasks.Dataflow;namespaceactor_model{//basic use and examples of actor model;//https://blog.jayway.com/2013/11/15/an-actor-model-implementation-in-c-using-tpl-dataflow/#comment -463337 Public Abstract classMessage {}//all actions are expressed in the form of Meg;//we all act as a message, let the message pass out, the real execution, to our specific actor to execute the drip; Public classDeposit:message { Public decimalAmount {Get;Set; } } //To check the balance we send a querybalance message Public classQuerybalance:message {//The result of the query should is sent as a message to another actor//In other words, the information is given to another actor to deal with the drop; PublicActor Receiver {Get;Set; } } //The final message is the result of the balance Chec Public classBalance:message { Public decimalAmount {Get;Set; } } Public Abstract classActor {Private ReadOnlyActionblock<message>_action; PublicActor () {_action=Newactionblock<message> (msg = { DynamicSelf = This; DynamicMess =msg; Self. Handle (mess); })); } Public voidSend (Message msg) {_action. Post (msg); } PublicTask Completion {Get{_action.complete (); return_action.completion; } } } //Each account has a balance. We want to is able to deposit money and check the balance//the performer of the actual action; Public classAccountactor:actor {Private decimal_balance; //Save Public voidHandle (Deposit msg) {_balance+ = Msg. Amount;//Deposite Money } //Check Balance Public voidHandle (querybalance msg) {//Check out the balance, called to our new actor to deal with the amount;//equivalent to creating a new ActoMsg. Receiver.send (NewBalance {Amount =_balance}); } } //We also need an actor that outputs the result of the balance query Public classOutputactor:actor { Public voidHandle (Balance msg) {Console.WriteLine ("Balance is {0}", Msg. Amount); } } classProgram {Static voidMain (string[] args) { varAccount =NewAccountactor (); varOutput =NewOutputactor (); Account. Send (NewDeposit {Amount = - }); Account. Send (Newquerybalance {Receiver =output}); Account.Completion.Wait (); Output.Completion.Wait (); Console.WriteLine ("done!"); Console.ReadLine (); } }}
After reading the basic understanding actor, but still very not thorough ~
C # Early identification of actor Model