c# - Efficient way to schedule multiple threads from ThreadPool to be exetuted in the future? -
i want utilize threads threadpool
run same procedure @ different time. here trying accomplish:
from have read, using .sleep()
delay execution terrible idea. improve thought ?
(unfortunately, can't utilize task parallel library, , limited .net 3.5)
i don't know how tpl useful here anyway. don't recall in involves scheduling things future execution.
.net includes 2 different basic timer classes (in system.timers , system.threading), , 3rd 1 forms (in case you're doing that). "go-to" api specific application.
one alternative might consider creating single thread consumes queue of scheduled tasks, implementing own timer. in 1 thread, you'd wind using thread.sleep(). yes, 1 want avoid that, in dedicated thread purpose, it's fine. whether you'd find more desirable utilize of 1 of timer classes, don't know, since don't understand resistance using 1 of timer classes.
note system.threading.timer class has "one-shot" mode. passing timeout.infinite repeat interval, timer callback executed once, after initial due time interval has elapsed. "management" necessary retain reference timer instance ensure it's not garbage-collected before timer period elapses.
it uses threadpool threads.
c# .net multithreading
No comments:
Post a Comment