开发者

Calling methods asynchronously from an MVC (v3) controller

开发者 https://www.devze.com 2023-03-19 22:09 出处:网络
I\'m writing a staff search application that queries two different Active Directories (one over a slow(ish) link) and combines the results into a List<userSummary> object which I then sort.

I'm writing a staff search application that queries two different Active Directories (one over a slow(ish) link) and combines the results into a List<userSummary> object which I then sort.

What is the best way to f开发者_Python百科ire off these request asynchronously so that they are both of retrieving the results at the same time ready to combine once both queries have completed? As both ADs contains many users this would speed up some of my wildcard searches no end.

Thanks,

Keeney


One way would be

Thread search1 = new Thread(new ThreadStart(Search1Method));
search1.IsBackground = true;
search1.Start();
Thread search2 = new Thread(new ThreadStart(Search2Method));
search2.IsBackground = true;
search2.Start();
search1.Join();
search2.Join();

You can also specify a timeout in the Joins so you don't wait an inordinate amount of time before responding.


Check out the AsyncController.

  • Using an Asynchronous Controller in ASP.NET MVC
0

精彩评论

暂无评论...
验证码 换一张
取 消