I am having a Repository method GetSubContracts() that is typically invoked as await and it works fine. I am trying to use the same in a non task/async operation such as a Button click Handler event. I would like to do on of the two options.
Call the async method without async as explained in the below article https://visualstudiomagazine.com/Blogs/Tool-Tracker/2019/10/calling-methods-async.aspx
Cast the Task<IEnumerable> to List
This is because I don’t get .ToList() option when using GetSubContacts in an non Task/await context.
The result. Is also not giving me a Cast or TypeOf options.
I tried various options including what seems to be similar topic here
Casting IEnumerable<T> to List<T>
On a general note, should I be adding to the above post or ask a new question here as I am doing now?
Code below.
public List<SubContract> SubContracts;
public List<SubContract> SubContractsOfSelectedSites = new List<SubContract>();
protected override async Task OnInitializedAsync()
{
Sites = (await SitesService.GetSites()).ToList();
SubContracts = (await SubContractsService.GetSubContracts()).ToList();
}
private void GenerateContractListHandler(MouseEventArgs args)
{
SubContractsTabDisabled = false;
//Get the result as Task<IEnumerable<SubContract>>
var result = (SubContractsService.GetSubContracts());
SubContractsOfSelectedSites =result.