Thursday 15 March 2012

c# - Multithreading Options -



c# - Multithreading Options -

i having bit of dilemma, or rather, unsure technology/method utilize , how. trying accomplish this:

hit web service, multiple times @ once, on different threads, based on number of "calls" have create web service. "calls" of course of study here exact same web service method, different parameters each call.

because working web services, assuming these services setup multiple calls @ once, , therefore, should able maximize speed , efficiency splitting work on multiple threads , making multiple calls @ once.

right now, creating set number of background workers main thread, , executing same code on each bgwkr. not fond of because copy-pasting code in each bgwkr dowork() method, , reading parameters list partitioned according how many bgwkrs have... limiting myself amount of bgwkrs create, , have partition list accordingly. of course, maintain log each phone call made, on each bgwkr, , merge when exit through own "sync" mechanism...

ideally logical opposite. is: partition list according maximum number of items per partition (e.g.: 10 per), , fire off number of threads needed create calls each partition created way.

as illustration result looking for, 10 per requirement: 100 items total yields 10 threads 10 items in each

150 items total yields 15 threads 10 items in each

it nice if didn't have manually sync of logs @ end too!

so question is: how accomplish this? i've heard talks task parallel library, after looking more, seems geared towards utilizing maximum number of cores accomplish single task?

is there way want without much manual intervention , copy-pasting of code blocks?

something this:

list<partition> partitions = (split total items partitions of 10); for(int i=0; i<partitions.count; i++) { somethreadtype trd = new somethreadtype() trd.codetoexecute => { foreach(item in partitions[i]) { syncedlogentries[i].addrange(call web service(item)); } } trd.waitmanager = somesyncmechanism(); trd.start(); } waitmanager.onallthreadsdone += someeventhandlermethod();

i know rough version, , there might more integrated ways of doing want, gives thought i'd accomplish. possible, , if so, how?

c# multithreading

No comments:

Post a Comment