Reputation: 393
So I'mtalking to a web service that needs me to do call a keep-alive method for every event that I'm subscribing. This can be up to 400 events at any given time.
Currently Im using System.Timers.Timer that runs no an interval. The problem is this seems to eat up my ThreadPool, because if I try to run something using ThreadPool.QueueWorkersItem() it can take it up to 20 seconds to run after it's queued.
Any idea how to run my keep-alive calls running without eating up the threadpool?
BR Tomas
Upvotes: 0
Views: 63
Reputation: 133995
It depends on how many of those events you have, how often you need to call the keep alive method, and how long it takes to make that call. ThreadPool.QueueUserWorkItem
is going to queue the method to be executed. If all of the threadpool threads are occupied, your work item will have to wait for a thread to be freed up. And for all the other items that were queued before it.
You probably should do as the commenter suggested and have a single dedicated thread that continually does the updates, probably by making async calls.
Upvotes: 1