c# - What Am I Missing About Reactive Extension Timers? -


i have this:

watchers   .toobservable() // needs observable   .selectmany(watcher =>         // working on each watcher     observable       // create timer watcher       .timer(watcher.starttime, timespan.fromhours(watcher.interval))         .selectmany(observable.fromasync(         async () => new { watcher, result = await checkfolder(watcher.path) })))    .subscribe(x => console.writeline(string.format("watcher: {0}\tresult: {1}\ttime: {2}", x.watcher.name, x.result, datetimeoffset.now))); // tell happened. 

which nice little bit of code this post got me started down road. goal ping web service (via checkfolder() method) every time timers publish, based on given start time , interval.

the trouble is, every time run program outputs single message first watcher, , program exits without error. gets first answer, , it's finished.

how wait other publications timers?

i'm positive i'm not asking question right way, little feedback me refine question.

thanks.

this because subscribe non-blocking call. i.e. if have;

static void main(string[] args) {   observable.timer(datetimeoffset.now, timespan.fromseconds(0.5))             .subscribe(x => console.writeline("got " + x)); } 

you'll find prints nothing (or maybe "got 0", depending on how pc feeling)

if stop main exiting, waiting key pressed, this:

static void main(string[] args) {     observable.timer(datetimeoffset.now, timespan.fromseconds(0.5))                .subscribe(x => console.writeline("got " + x));     console.readkey(); } 

then should keep printing out values until press key.

the thing remember having activating subscription, isn't enough keep programming running. if you're writing application ui, you'll have message loop - program alive until close window. isn't case console apps, once end of main, that's end of program.

so need find way avoid app exiting before you're reading. waiting specific key pressed common way it, may work you. e.g.

static void main(string[] args) {     observable.timer(datetimeoffset.now, timespan.fromseconds(0.5))               .subscribe(x => console.writeline("got " + x));      while (console.readkey().key != consolekey.q)     {     } } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -