How to use actors of akka.net in MVVM?












0














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"));
}



  1. Call the responsible actor directly, answer is send to deadletters. Are there more complex examples?

  2. Would receive the answer and could call callbacks of the mainviewmodel, but gives me InvalidOperationException "Call from invalid thread"

  3. Seems to be the only way to get the result of the call


I am wondering how to fill ListViews or ComboBoxes by Actor messagings.










share|improve this question



























    0














    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"));
    }



    1. Call the responsible actor directly, answer is send to deadletters. Are there more complex examples?

    2. Would receive the answer and could call callbacks of the mainviewmodel, but gives me InvalidOperationException "Call from invalid thread"

    3. Seems to be the only way to get the result of the call


    I am wondering how to fill ListViews or ComboBoxes by Actor messagings.










    share|improve this question

























      0












      0








      0







      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"));
      }



      1. Call the responsible actor directly, answer is send to deadletters. Are there more complex examples?

      2. Would receive the answer and could call callbacks of the mainviewmodel, but gives me InvalidOperationException "Call from invalid thread"

      3. Seems to be the only way to get the result of the call


      I am wondering how to fill ListViews or ComboBoxes by Actor messagings.










      share|improve this question













      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"));
      }



      1. Call the responsible actor directly, answer is send to deadletters. Are there more complex examples?

      2. Would receive the answer and could call callbacks of the mainviewmodel, but gives me InvalidOperationException "Call from invalid thread"

      3. Seems to be the only way to get the result of the call


      I am wondering how to fill ListViews or ComboBoxes by Actor messagings.







      .net wpf xaml akka.net






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 21:03









      SlesaSlesa

      10518




      10518
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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.






          share|improve this answer





















          • Yes, understood. The threading thing is solvable. But how would I really create an actor, which wants to, let's say, get the content of a listview? Would the Form/Widget/Whatever be an actor on its own to be able to receive the answer? Or would I use eventing to redirect the incoming data? But then it probably won't fit with the streaming stuff, would it? I am looking here for a good/best practice, you know
            – Slesa
            Nov 23 '18 at 21:52










          • This is more design issue (not fit for StackOverflow question), but general intuition is to keep the Single Responsibility Principle. If you want to use an actor for updating UI controls, don't use it for managing i.e. business domain logic.
            – Bartosz Sypytkowski
            Nov 25 '18 at 8:57











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382582%2fhow-to-use-actors-of-akka-net-in-mvvm%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          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.






          share|improve this answer





















          • Yes, understood. The threading thing is solvable. But how would I really create an actor, which wants to, let's say, get the content of a listview? Would the Form/Widget/Whatever be an actor on its own to be able to receive the answer? Or would I use eventing to redirect the incoming data? But then it probably won't fit with the streaming stuff, would it? I am looking here for a good/best practice, you know
            – Slesa
            Nov 23 '18 at 21:52










          • This is more design issue (not fit for StackOverflow question), but general intuition is to keep the Single Responsibility Principle. If you want to use an actor for updating UI controls, don't use it for managing i.e. business domain logic.
            – Bartosz Sypytkowski
            Nov 25 '18 at 8:57
















          0














          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.






          share|improve this answer





















          • Yes, understood. The threading thing is solvable. But how would I really create an actor, which wants to, let's say, get the content of a listview? Would the Form/Widget/Whatever be an actor on its own to be able to receive the answer? Or would I use eventing to redirect the incoming data? But then it probably won't fit with the streaming stuff, would it? I am looking here for a good/best practice, you know
            – Slesa
            Nov 23 '18 at 21:52










          • This is more design issue (not fit for StackOverflow question), but general intuition is to keep the Single Responsibility Principle. If you want to use an actor for updating UI controls, don't use it for managing i.e. business domain logic.
            – Bartosz Sypytkowski
            Nov 25 '18 at 8:57














          0












          0








          0






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 8:55









          Bartosz SypytkowskiBartosz Sypytkowski

          5,053925




          5,053925












          • Yes, understood. The threading thing is solvable. But how would I really create an actor, which wants to, let's say, get the content of a listview? Would the Form/Widget/Whatever be an actor on its own to be able to receive the answer? Or would I use eventing to redirect the incoming data? But then it probably won't fit with the streaming stuff, would it? I am looking here for a good/best practice, you know
            – Slesa
            Nov 23 '18 at 21:52










          • This is more design issue (not fit for StackOverflow question), but general intuition is to keep the Single Responsibility Principle. If you want to use an actor for updating UI controls, don't use it for managing i.e. business domain logic.
            – Bartosz Sypytkowski
            Nov 25 '18 at 8:57


















          • Yes, understood. The threading thing is solvable. But how would I really create an actor, which wants to, let's say, get the content of a listview? Would the Form/Widget/Whatever be an actor on its own to be able to receive the answer? Or would I use eventing to redirect the incoming data? But then it probably won't fit with the streaming stuff, would it? I am looking here for a good/best practice, you know
            – Slesa
            Nov 23 '18 at 21:52










          • This is more design issue (not fit for StackOverflow question), but general intuition is to keep the Single Responsibility Principle. If you want to use an actor for updating UI controls, don't use it for managing i.e. business domain logic.
            – Bartosz Sypytkowski
            Nov 25 '18 at 8:57
















          Yes, understood. The threading thing is solvable. But how would I really create an actor, which wants to, let's say, get the content of a listview? Would the Form/Widget/Whatever be an actor on its own to be able to receive the answer? Or would I use eventing to redirect the incoming data? But then it probably won't fit with the streaming stuff, would it? I am looking here for a good/best practice, you know
          – Slesa
          Nov 23 '18 at 21:52




          Yes, understood. The threading thing is solvable. But how would I really create an actor, which wants to, let's say, get the content of a listview? Would the Form/Widget/Whatever be an actor on its own to be able to receive the answer? Or would I use eventing to redirect the incoming data? But then it probably won't fit with the streaming stuff, would it? I am looking here for a good/best practice, you know
          – Slesa
          Nov 23 '18 at 21:52












          This is more design issue (not fit for StackOverflow question), but general intuition is to keep the Single Responsibility Principle. If you want to use an actor for updating UI controls, don't use it for managing i.e. business domain logic.
          – Bartosz Sypytkowski
          Nov 25 '18 at 8:57




          This is more design issue (not fit for StackOverflow question), but general intuition is to keep the Single Responsibility Principle. If you want to use an actor for updating UI controls, don't use it for managing i.e. business domain logic.
          – Bartosz Sypytkowski
          Nov 25 '18 at 8:57


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382582%2fhow-to-use-actors-of-akka-net-in-mvvm%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith