keeney
keeney

Reputation: 933

Calling methods asynchronously from an MVC (v3) controller

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 fire 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

Upvotes: 0

Views: 463

Answers (2)

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.

Upvotes: 1

Related Questions