I am rarely use task / await to call my function. please have a look at my code example. i am using .net v4.5.2.
private async void button1_Click(object sender, EventArgs e)
{
bool retvalue = false;
var periodTimeSpan = TimeSpan.FromSeconds(10);
var task1 = SimulateJob();
var task2 = Task.Delay(periodTimeSpan);
await Task.WhenAll(task1, task2);
retvalue = (bool) task1.Result;
}
private Task<bool> SimulateJob()
{
bool status = false;
Task.Delay(10000);
status = true;
return Task.FromResult(status);
}
please run the code and understand that SimulateJob() function getting called twice.
in really my SimulateJob() function loads big excel file into spread sheet control. if that function gets called twice then it will be problem for me.
how to change my code in such a way that when this line will execute await Task.WhenAll(task1, task2); then my SimulateJob() function will be called.
in real code SimulateJob() function load multiple big excel file. i saw when this line execute var task1 = SimulateJob(); then my routine load all those big files which is my problem. i want that when this line would execute await Task.WhenAll(task1, task2); then my SimulateJob function should load those big excel file. so tell me what i need to change in my code example.
please help me to handle this situation. thanks
SimulateJob? - Abhilash Augustinevar task1 = SimulateJob();then my routine load all those big files which is my problem. i want that when this line would execute ` await Task.WhenAll(task1, task2);` then my SimulateJob function should load those big excel file. so tell me what i need to change. thanks - user15940620awaitnorWhenAllare responsible for starting anything. You give them already runningTasks, and they wait for them to finish. It sounds like youSimulateJobmethod, despite returning aTaskis actually synchronous. - Damien_The_Unbeliever