I am using Parallel.Invoke
to execute single method with different input values, but I want to get return value of the method.
How can I get it ?
public class Work
{
public static void Main()
{
Parallel.Invoke(() => DoWork("Raju"),
() => DoWork("Ramu"));
}
public static string DoWork(string data)
{
return "testing" + data;
}
}
In above method I want get DoWork
return value.
Just handle the return value like this:
string result1, result2;
Parallel.Invoke(() => result1 = DoWork("Raju"),
() => result2 = DoWork("Ramu"));
Also remember that whenever you do something in parallel you need to be careful to avoid data races and race conditions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With