Potentially weird request, but I'm attempting to simulate a method call concurrently with the end goal being that i don't care which call to the method reaches it first... the method itself is synchronous (for now) and therefore i know and accept that it will block, i simply don't care which request makes it there first..
this is more of a thought exercise, so if i do something like this, is it doing what i think it's doing? i.e. running the method calls on different threads?
Task<MyObject> t1 = Task.Run(() => MethodToRun("param1"));
Task<MyObject> t2 = Task.Run(() => MethodToRun("param2"));
await Task.WhenAll(t1, t2); // block, and wait for results, i think?
var r1 = t1.Result;
var r2 = t2.Result;
or, will this always end up executing t1
first regardless?
i thought about adding the tasks to a list, and then kicking them all off perhaps..
var taskList = new List<Task<MyObject>>
{
new Task<MyObject>(() => MethodToRun("param1"));
new Task<MyObject>(() => MethodToRun("param2"));
};
Parallel.ForEach(taskList, t => t.Start());
await Task.WhenAll(taskList);
var r1 = taskList[0].Result;
var r2 = taskList[1].Result;
is that actually any different?