0

I am learning about Tasks and running them in Parallel and for my test I had 3 functions that I would run in parallel each returning a string. I wanted to add each of those returned strings to another string and display the final result.

string result;
Parallel.Invoke(() => SomeFunction(),
                () => AnotherFunction(),
                () => AndAnother());


private string SomeFunction()
{
   return "1";
}

private string AnotherFunction()
{
   return "2";
}

private string AndAnother()
{
   return "3";
}

How would I (if possible) get the values ("1", "2", "3") so that I could set it to result?

Apologies in advance, I am quite new to programming and this is my first post I believe so if the structure of the question is off or could have been presented in a better way please let me know!

ericjets
  • 11
  • 1
  • Somewhat related: [Updating different properties of same object in Parallel.Invoke is thread-safe?](https://stackoverflow.com/questions/69140421/updating-different-properties-of-same-object-in-parallel-invoke-is-thread-safe) – Theodor Zoulias Nov 15 '21 at 22:11

0 Answers0