c# - Threading, BackgroundWorker or Task, numerous objects processed by the same method -


i have list of t objects need processed, , speed processing of list, farmed out asynchronous process. each object processed same method, have couple questions regarding various asynchronous strategies:

  1. is backgroundworker or task (tpl) preferable?
  2. am correct in saying whichever method chosen, list of backgroundworker or task objects need instantiate new class containing method process t? in other words, if classa creating backgroundworker or task objects, should not point classa.processobject(t t), instead instantiate new classb().processobject(t t) method work?

you're free use whichever tool want accomplish task. 2 not interchangeable, in have different (although overlapping) design goals. prefer can't answer.

whether want of workers execute method of same instance of object or different instance entirely dependent on context. neither inherently wrong, long understand whether or not various threads acting on same instance or not, , write code accordingly. both, in right circumstances, can entirely acceptable. comes down whether want various threads share state or not, , whether given state designed accessed multiple threads.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -