It seems that it is very easy to use akka.net in a console app or in unit tests.
But I wanted to try out some actors for a simple login method: open a splash screen, send a login command, close the splash screen when login was ok. Now the answer is sent to the sender, which is an actor. Awaiting the answer of an Ask call would block the UI. The MainViewModel is already derived from a base class, so make it an actor is not an option.
public void OnStartupCommand(EventArgs args)
{
_splashScreen = new SplashScreenView();
_splashScreen.Show();
// [1]
_actorSystem.ActorSelection("/user/system").Tell(new Login("Me"));
// [2]
var mainWindowActor =_actorSystem.ActorOf(Props.Create(() => new
MainWindowActor(this)), "mainwindow");
mainWindowActor.Tell(new Login("me"));
// [3]
var result = await _actorSystem.ActorSelection("/user/system").Ask(new Login("me"));
}
I am wondering how to fill ListViews or ComboBoxes by Actor messagings.
By default most of akka actors are scheduled in background threads, therefore they cannot make direct updates on the UI (only UI/primary thread of the application is allowed to do that). If you want to spawn an actor on UI thread, you need to configure it to use SynchronizedDispatcher .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.