I want to wrap 3rd party function to Task to be able to await for finish the callback function. This is what I would like to achieve:
public MyClass MyProperty {
get
{
if (myProperty == null)
myProperty = LoadMyValue("1234");
return myProperty ;
}
set
{
myProperty = value;
}
}
public MyClass LoadMyValue(string id) {
return MyClassTools.LoadMyValue(id);
}
and in MyClassTools
static public MyClass LoadMyValue(string id) {
3rdPartyApi.Call(id, Callback);
// here I want to return Callback result
}
static MyClass Callback(3rdPartyResult result) {
return new MyClass(result);
}
How to use here Tasks and async/await to be able return Callback result directly from function LoadMyValue?