我有一个async
成员,最终需要调用一些UI更新,从服务器获得一些数据后。
我想我需要像BeginInvokeOnMainThread
或Dispatcher.Invoke
这样的东西,但这两个在Uno上下文中似乎都不被识别。
这是我所拥有的精华:
public async Task LoadList()
{
...
// get data
Uri uri = new Uri("https://...");
response = await httpClient.GetAsync(uri);
// display
BeginInvokeOnMainThread () =>
{
... update the UI ...
});
}
但我得到错误CS0103 The name 'BeginInvokeOnMainThread' does not exist in the current context UnoTest.Droid, UnoTest.UWP, UnoTest.Wasm
BeginInvokeOnMainThread
/Dispatcher.Invoke
/Control.Invoke
从来都不是一个好主意。
Uno应该有一个SynchronizationContext
被await
自动使用,所以手动线程封送不应该是必要的:
public async Task LoadList()
{
...
// get data
Uri uri = new Uri("https://...");
response = await httpClient.GetAsync(uri);
// display
... update the UI ...
}