.net - c# run a thread each one minute despite the thread time -
.net - c# run a thread each one minute despite the thread time -
i want run process every 1 minute, have been told timer
working every x min + time required process finish
. want thread work every 1
min though thread process may maintain working 1 hour.
i hope got me, in final image, may have 10 threads working together.
is possible ?
depends on timer. simple test shows system.threading.timer
works way want:
var timer = new timer(s => { "start".dump(); thread.sleep(10000); "hi!".dump(); }, null, 1000, 1000); thread.sleep(20000); timer.dump();
the callback executes every sec though takes 10 seconds execute.
this because callback particular timer posted threadpool, while e.g. system.windows.forms.timer
tied ui thread. of course, if start new thread (or queue work, or start new task etc.) in callback of winforms timer, work in similar (albeit less precise) way.
using right tool job makes things much easier :)
c# .net multithreading
Comments
Post a Comment