Take a look at the parallel task library (TPL) that was introduced in the .NET Framework 4 (i.e., with Visual Studio 2010). More specifically, from the point of view of TPL, your problem can be solved using the parallelism task .
Now I'm not a TPL expert at all, but the documentation suggests that you should do what you want, Parallel.Invoke :
using System.Threading.Tasks; … List<wrecords> records1 = null; List<wrecords> records2 = null; List<wrecords> records3 = null; // ^ Initialize these to any default value to prevent a compile-time error. // The compiler cannot know that below delegates will actually be called, // so without the initialization you would soon get a "use of unassigned // variable" error. Parallel.Invoke( () => { records1 = Search.GetrecordsofAAA(heart); }, () => { records2 = Search.GetrecordsofBBB(heart); }, () => { records3 = Search.GetrecordsofCCC(heart); } );
PS: As soon as your methods are executed in parallel, you must make sure that none of them has side effects that can lead to the malfunctioning of other methods. (For example, if these methods read and modify the same static fields that belong to your Search class, this can lead to problems.)
source share