On the selection changed event I am accessing the data from one of my tables. But the “Exception has been thrown by the target of an invocation” is thrown.
var query = conn.Table<auto_fares>().Where(x => x.city == cbCity.SelectedItem);
var result = await query.ToListAsync();
foreach (var item in result)
{
txtDistance.Text = item.min_km.ToString();
lblDayFare.Text = item.min_fare.ToString();
lblNightFare.Text = item.night_charges.ToString();
}
After adding the Dispose statement i am getting the following error as
“The await operator can only be used within an async lamhda expression. Consider making this lamhda expression with the ‘async’ modifier.”
How can I solve this?
Try re-writing your code like this:
You’re trying to access a UI component (cbCity.SelectedItem) from a non-UI thread (await query.ToListAsync() )