C# Multithreading Model -
I have a C # single threaded application and currently working to make it multi-threaded with the use of thread pools. Used to be.
while (1) {do_sometask ()); waiting times); }
And it is almost repeated for several times in the new scenario that has several threads which are above. I can easily implement it by increasing the number of threads based on those tasks, where all the threads do some work and wait forever.
The problem here is that I have the number of work, so I can not create 500 threads just blindly. I thought of using Threadpool, but because almost every thread will always be free for new tasks in the loop and the queue, I'm not sure which other models will use.
I am looking for an idea or solution where I could break the loop in the thread and free it instead of waiting, but after waiting, we returned and resumed the same work ( When time is over, using something like timer / timestamp checking is done).
With it, I can use limited threads (like in a thread pool) and can complete those tasks which are waiting (in fact) waiting for the old thread.
Help is really appreciated.
If you have everything that happens from time to time, then what do you think you want There are a bunch of timers that make a timer for each task, when it is appropriate, a fire will occur, so if you have two different tasks:
using System.Threading; // Task 1 timer works for 1 timer 1 timer 1 timer = new timer (s => dosset 1 (), blank, timespace, transmission (1), timespace from min mints (1)); // Task 2 happens once every 47 seconds timer task 2 timer = new timer (s => doset 2 (), faucet, timespace.foamseconds (47), timespace.formsconds (47); The timer is a very light object, so having a whole bunch of them does not really have a problem. The timer only urges that it takes CPU resources. The callback method is executed on the pool thread.
There is a potential problem. If there are too many timers with the same duration, then the callback will be called at all at the same time. Threadpool should handle the number of consistently compatible by hand, but I'm sure But if your time of waiting is reduced, then it is working well.
If you have a short wait time (less than a second) So, maybe you have a different technique. Tells the star that if necessary.
Comments
Post a Comment