I have a service that should work forever to track a single server. To do this, I have 5 tasks that must be performed by the service (5 at the moment there will be hundreds).
I created threadpool with a maximum of 5 threads. There is a queue that threads use to get the task, then each thread processes the task, and then queues it again. The queue contains objects with 5 small attributes.
After starting the service for a while, I get an OutOfMemoryException exception in the line where I execute this:
ThreadPool.QueueUserWorkItem(currentJob.ProcessJob, (object)timeToWwait);
timeToWwait is an int, and I no longer use it.
The context is as follows:
ThreadPool.SetMinThreads(0, 0); ThreadPool.SetMaxThreads(5, 5); while (true) { bool processJob = false; bool checkedFrontEnd = false; _qLock.EnterWriteLock(); try { if (_jobQueue.Count > 0) { currentJob = _jobQueue.Dequeue(); // currentJob.IsActive = true; // processJob = true; } } finally { _qLock.ExitWriteLock(); } ThreadPool.QueueUserWorkItem(currentJob.ProcessJob, (object)timeToWwait); //currentJob.ProcessJob((object)timeToWwait); _qLock.EnterWriteLock(); try { _jobQueue.Enqueue(currentJob); } finally { _qLock.ExitWriteLock(); }
Do you have any suggestions?
source share