I try to test this structure but it never works.
I believe I have misunderstood it or lack knowledge in concurrency.
Please light me to the correct direction.
I call a save method but this never saves.
My code :
public async Task<MyObject> GetMyObject_ById(int id)
{
var responseDto = await this.RestApi.QueryMyObject_ById(id).ConfigureAwait(false);
if (responseDto != null)
{
return this.mapper.Map<MyObject>(responseDto);
}
else
{
return null;
}
}
public async Task<MyObject> UpdateMyObject(int id, MyObject updatevalue)
{
var dto = this.mapper.Map<MyObjectDto>(updatevalue);
var updateinfo = await this.RestApi.Update(id, dto).ConfigureAwait(false);
return this.mapper.Map<MyObject>(updateinfo);
}
private void Save()
{
foreach (MyObject pb in this.ListToSave)
{
this.SaveValue(pb.Id, pb.Status));
}
}
private async Task<MyObject> SaveValue(int id,string status)
{
var info = this.GetMyObject_ById(id).Result;
info.Status = status;
return await this.RestApi.UpdateMyObject(id, info).ConfigureAwait(false);
}
Savean entry method (bind to button event)? You can convert theSavemethod to async type and inovkeSaveValueusing await. Don't call aysnc method in sync contextawaiting SaveValue.Resultexactly because of this. You shouldn't do that, though. Go async all the way. Oh and - do not mistake "async" for "concurrency".