system.reactive - Whats a good way to run periodic tasks in c# using Rx with a single concurrent execution restriction? -


i want run periodic tasks in restriction @ 1 execution of method running @ given time.

i experimenting rx, not sure how impose @ once concurrency restriction.

var timer = observable.interval(timespan.frommilliseconds(100)); timer.subscribe(tick => dosomething()); 

additionally, if task still running, want subsequent schedule elapse. i.e don't want tasks queue , cause problems.

i have 2 such tasks execute periodically. tasks being executed synchronous. but, make them async if there necessity.

you should have tested code because rx imposes already.

try test:

void main() {     var timer = observable.interval(timespan.frommilliseconds(100));     using (timer.do(x => console.writeline("!")).subscribe(tick => dosomething()))     {         console.readline();     } }  private void dosomething() {     console.write("<");     console.write(datetime.now.tostring("hh:mm:ss.fff"));     thread.sleep(1000);     console.writeline(">"); } 

when run you'll kind of output:

! <16:54:57.111> ! <16:54:58.112> ! <16:54:59.113> ! <16:55:00.113> ! <16:55:01.114> ! <16:55:02.115> ! <16:55:03.116> ! <16:55:04.117> ! <16:55:05.118> ! <16:55:06.119 

it ensuring there's no overlap.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -