Tests
I have a function f1(string, string) which takes 4 seconds to execute (irrelevant what it does). Tested this by calling f1("a", "b") in main.
Calling
Console.WriteLine(f1("a", "b"));
Console.WriteLine(f1("a", "b"));
will wait 4 seconds for the first function to finish, prompt the return, wait another 4 seconds, prompt the second result all fine and dandy.
I've tried doing this in parallel by creating two separate anonymous threads with lambda like so:
new Thread(() => {Console.WriteLine(f1("a", "b")); }).Start();
new Thread(() => {Console.WriteLine(f1("a", "b")); }).Start();
Since I have a dual core processor and the functions are processing heavy (OS balanced this out very well) I have gotten both prompts after 4 seconds (instead of 8) so I know it worked in parallel.
Question
How can I write a function f1Async(string, string) which would initially call f1(string, string) albeit on a different thread every time (like I've done manually in main)? In order to know what the output of f1Async will be I have to wait for the thread to finish thus calling f1Async() two times in a row will result in the function waiting for one thread to finish before moving on to the second call.