Код: Выделить всё
public class ViewModel
{
public ObservableCollection Data { get; set; }
async public ViewModel()
{
Data = await GetDataTask();
}
public Task GetDataTask()
{
Task task;
//Create a task which represents getting the data
return task;
}
}
Модификатор async< /code> недействителен для этого элемента
Конечно, если я оберну стандартный метод и вызову его из конструктора:< /p>
Код: Выделить всё
public async void Foo()
{
Data = await GetDataTask();
}
Код: Выделить всё
GetData().ContinueWith(t => Data = t.Result);
Подробнее здесь: https://stackoverflow.com/questions/814 ... s-be-async
Мобильная версия