I have the following methods:
public int getData() { return 2; } // suppose it is slow and takes 20 sec // pseudocode public int GetPreviousData() { Task<int> t = new Task<int>(() => getData()); return _cachedData; // some previous value _cachedData = t.Result; // _cachedData == 2 }
I do not want to wait for the result of an already running operation.
I want to return _cachedData and update it after Task completes.
How to do it? I am using .net framework 4.5.2
user5515846
source share