c# - Reset and Dispose observable subscriber, Reactive Extensions -


suppose have :

    public class uploaddicomset  {      public uploaddicomset()     {         var cachcleantimer = observable.interval(timespan.fromminutes(2));         cachcleantimer.subscribe(checkuploadsetlist);         //start subscriber     }     void checkuploadsetlist(long interval)     {         //stop , dispose subscriber     }     public void adddicomfile(sharedlib.dicomfile dicomfile)     {         //renew subscriber, call checkuploadsetlist 2 minutes later     } } 

1- in checkuploadsetlist want dispose or finish observable

2- in adddicomfile want reset

as comment in methods.

update:

i can timer as:

 public class uploaddicomset : importbaseset {     timer _timer;     public uploaddicomset()     {         _timer = new timer(checkuploadsetlist, null, 120000, timeout.infinite);     }      void checkuploadsetlist(object state)     {         logging logging = new logging(logfile);         try         {             _timer.dispose(); //stop subscription                               //dispose         }         catch (exception exp)         {             logging.log(errorcode.error, "checkuploadsetlist() failed..., exp:{0}", exp.tostring());         }     }     public void adddicomfile(sharedlib.dicomfile dicomfile)     {         _timer.change(120000, timeout.infinite);     } } 

thanks in advance.

using reactive extension timer function seems bit overkill me. why not use ordinary timer this, , start/stop @ given times?

let me give idea.

public class uploaddicomset : importbaseset {     idisposable subscription;      public void createsubscription()     {         var cachcleantimer = observable.interval(timespan.fromminutes(2));          if(subscription != null)             subscription.dispose();          subscription = cachcleantimer.subscribe(s => checkuploadsetlist(s));     }      public uploaddicomset()     {         createsubscription();         // other things     }      void checkuploadsetlist(long interval)     {         subscription.dispose(); // stop subscription         // other things     }      public void adddicomfile(sharedlib.dicomfile dicomfile)     {         createsubscription(); // reset subscription go off in 2 minutes         // other things     } } 

background material

i can recommend these sites:

http://www.introtorx.com/

http://rxwiki.wikidot.com/101samples


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -