c# make function async code example
Example 1: c# async constructor
public class ViewModel
{
public ObservableCollection<TData> Data { get; set; }
async public static Task<ViewModel> BuildViewModelAsync()
{
ObservableCollection<TData> tmpData = await GetDataTask();
return new ViewModel(tmpData);
}
private ViewModel(ObservableCollection<TData> Data)
{
this.Data = Data;
}
}
Example 2: can I call an action async c#
public async Task ExecuteAsync(Func<Task> func)
{
try
{
await func();
}
finally
{
}
}