c# - .NET Multi-thread a background process with a thread limit? -


i'm relatively new parallel programming , have need run background process on different threads.

the scenario - cause first background process run - take 45 seconds (for example) complete. meanwhile, @ arbitrary point after first background process runs, event occurs in turn causes second background process run - 20 seconds in. don't want wait 25 more seconds first process complete, want second process running right away on thread. but, want limit number of threads can spurned up.

do need create sort of queuing class backgroundworker objects or similar? best approach scenario?

your best bet use task parallel library accomplish this. instead of spinning threads run tasks, start new tasks using task.run(), or similar.

the task parallel library uses taskscheduler execute tasks on thread pool. taskscheduler tries optimize number of threads in thread pool increase throughput. because taskschedule reuses threads 1 task next, unlikely need limit number of threads in thread pool.

for more information taskscheduler in general see: http://msdn.microsoft.com/en-us/library/dd997402.aspx

if sure need limit number of threads, can extend taskscheduler class: http://msdn.microsoft.com/en-us/library/ee789351.aspx


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -