asp.net mvc - how to be sure its parallel in c# -


this code have written days, want know running in parallel . part of controller in mvc code.

namespace newsreader.controllers {     public class testcontroller : controller     {         public async task<actionresult> index()         {             using (var db = new applicationdbcontext())             {                 var categorylist = db.categories.select(item => item.name).tolist();                 var khabaronline = khabaronlinetask(categorylist);                 var isna = isnatask(categorylist);                 await task.whenall(khabaronline, isna);                 var newslist = new list<newsdetail>();                 newslist.addrange(khabaronline.result);                 newslist.addrange(isna.result);                 return view(newslist);             }        }         public task<list<newsdetail>> khabaronlinetask(list<string> categorylist)         {            var ac = new agenciesclass();            return task.run(() => ac.khabaronline(categorylist));         }      

assuming both tasks code indeed try run in parallel result of synchronously starting 2 tasks task.run(().... may endup serializing each other due bugs in implementation/explicit synchronization, @ least start in parallel.

await task.whenall guarantee code continues after both tasks completed.

note: code consistently uses async/await or lower level run/continuewith easier read/reason about, mixing way did fine too.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -