visual studio 2010 - TPL Task return values -
i have application face recognition system received camera frames around 30 : 50 frame/second depending on camera type , each frame have anther function persons on , each persons in person in current frame check if person exist in database or not database records it’s around 100,000 records , steps made ever frame
i rewrite previous question simple c# statement more clear
// frame camera can consider it's inside loop (int frame = 1; frame < 50; frame++) { // each fram person insied frame // list<persons> foreach (var perosn in allpersons_inframe) { // each person need check //against database recored foreach (var recored in database) { // perosn exist in database // give me person id } } }
till application working without problems have anther dea make task more simple , take small time comparing current time taken .i need used parallel programming "tpl" how : need divide database record 5 part each part around 20,000 record , process 5 parts in parallel way , wait till 5 part finished , check if part have result main final result
but don’t know how implant idea hope question clear
so please if 1 has idea me implement idea grateful him
i didn't test, hope helps.
// define logic here. func<ienumerable<person>, string> yourlogichere = null; // define way compare task result here. func<ienumerable<task<string>>, string> dealwiththetaskresultshere = null; collection<person> persons = new collection<person>(); task<string> maintask = new task<string>(tmpobj => { var tmppersons = tmpobj collection<person>; if (tmppersons != null) { int interval = (int)math.ceiling(tmppersons.count / 5d); int index = 0; collection<task<string>> subtasks = new collection<task<string>>(); while (index < tmppersons.count) { task<string> subtask = new task<string>( (tmpsubpersons) => { return yourlogichere((ienumerable<person>)tmpsubpersons); }, tmppersons.skip(index).take(interval).toarray(), taskcreationoptions.attachedtoparent); index += interval; subtasks.add(subtask); } foreach (var subtask in subtasks) { subtask.start(); } foreach (var subtask in subtasks) { subtask.wait(); } return dealwiththetaskresultshere(subtasks); } else return string.empty; }, persons); maintask.start(); maintask.wait(); return maintask.result;
Comments
Post a Comment