Slow operations in the Model-View-Presenter

How do you handle slow operations in Model-View-Presenter (or MVC or MV-VM or any other option that you use)?

If you have slow work in WinForms or SWT / JFace or any working environment that you use, you should run it in the background thread to avoid blocking the application completely. Where do you deal with this?

I see a couple of solutions, but I'm not quite happy with them:

  • If a call to a call always calls the lead in the background thread. This means that the view should handle the fact that all calls from the presenter are likely to be received from the background thread.

  • Ask the call to call the master in the main thread. Then the presenter will have to return to viewing when performing a slow operation so that it can be launched in the background.

What do you usually do?

EDIT: I just saw this article: http://www.codeproject.com/KB/threads/ThreadedExecuter.aspx . This is basically implementation 2. Has anyone tried something like this?

+3
source share
4 answers

. . (, ) , . , tamberg

+1

tamberg (.. ).

, , , :

  • ( BackgroundWorker)

, (, , ).

+1

asynccallback, , GWT, witch, , , , o

:

class ServiceX {
     void doFoo(x arg , y arg2 , callback arg3){
          //do in your thread 
          arg3.success("with return variables you need")

          // or
          arg3.failed("with exception for example");

     }

}

interface Callback {
     void success(args...);
     void failed(args ...);
}


in your view :

// do 
ServiceX bar = // get your service

bar.doFoo(a1,a2,new CallBack(){
    void succes(args ...){
    }

    void failed(args ...){
    }
});
+1

. . AOP (spring.net) , IView. , , . :

// ...
[RunInBackground]
public void TakeSomeTimeToRetrieveSomeItems
{
  var items = _svc.GetSomeItemsFromTheWeb();
  _view.ShowItems(items); // synced to UI automatically; blocks in presenter
}

:

// ...
public void ShowItems(IList<Item> items)
{
  itemBindingSource.DataSource = items;
}

, , , .

+1

Source: https://habr.com/ru/post/1702229/


All Articles