.net - Queuing work items to the thread pool using System.Threading.Task -


i'd know (if any) straightforward way of queuing work items (delegates) thread pool in .net 4.5 using system.threading.task objects. want replicate queuing functionality of threadpool.queueuserworkitem() method tasks. please correct me if i'm wrong, far know work items enqueued using method guaranteed executed in order enqueued (maybe i'm wrong multi-processor scenarios). have write code behaves same, using tasks.

i working on portable class library, that's why can't use threadpool.queueuserworkitem(), instead have rely on tasks objective. technique suggest? default task scheduler suitable requirement?

what ask tasks already. task wrapper around lambda default gets queued execute on threadpool. on top of that, tasks add continuations, exception handling, cancellation , many convenience functions make multi-threading lot easier.

if don't want use threadpool, can create own taskscheduler , use when creating new task. taskscheduler receives task , schedules execution.

the default taskscheduler uses threadpool.queueuserworkitem plus work-stealing magic , multiple queue handling. other implementations can use priority queue, set own limits on maximum or minimum number of threads or whatever technique author wants use.

edit

i didn't notice portable part beginning. question "does pcl provide taskscheduler uses threadpool or have create own"?

.net 4+ provides threadpooltaskscheduler. unfortunately, seems missing pcl subset. looks may have create own taskscheduler or use nuget package add platform specific implementations.

somehow, think threadpooltaskscheduler bad choice windows phone project

after diggind using resharper , .net's debug symbols, think pcl finds available platform taskscheduler implementations itself.

in .net 4.0, taskscheduler.default returns instance of threadpooltaskscheduler, interal bcl class. in pcl subset, taskscheduler.default returns null , threadpooltaskscheduler not available.

the source code threadpooltaskscheduler probalby available microsoft's reference source servers, can browse @ dotnetframework.org

i created pcl class returns new task , called .net 4.5 console application see taskscheduler use. found pcl class used threadpooltaskscheduler.

i haven't tried windows 8 or windows phone 8 project yet, although suspect i'll each platform's default taskscheduler.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -