code_junkie

Slow operations in the Model-View-Presenter pattern

Nov 13th, 2011
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. class ServiceX {
  2. void doFoo(x arg , y arg2 , callback arg3){
  3. //do in your thread
  4. arg3.success("with return variables you need")
  5.  
  6. // or
  7. arg3.failed("with exception for example");
  8.  
  9. }
  10.  
  11. }
  12.  
  13. interface Callback {
  14. void success(args...);
  15. void failed(args ...);
  16. }
  17.  
  18.  
  19. in your view :
  20.  
  21. // do
  22. ServiceX bar = // get your service
  23.  
  24. bar.doFoo(a1,a2,new CallBack(){
  25. void succes(args ...){
  26. }
  27.  
  28. void failed(args ...){
  29. }
  30. });
  31.  
  32. // ...
  33. [RunInBackground]
  34. public void TakeSomeTimeToRetrieveSomeItems
  35. {
  36. var items = _svc.GetSomeItemsFromTheWeb();
  37. _view.ShowItems(items); // synced to UI automatically; blocks in presenter
  38. }
  39.  
  40. // ...
  41. public void ShowItems(IList<Item> items)
  42. {
  43. itemBindingSource.DataSource = items;
  44. }
Add Comment
Please, Sign In to add comment