Uno平台:从异步线程调用UI更新



我有一个async成员,最终需要调用一些UI更新,从服务器获得一些数据后。

我想我需要像BeginInvokeOnMainThreadDispatcher.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应该有一个SynchronizationContextawait自动使用,所以手动线程封送不应该是必要的:

public async Task LoadList()
{
  ...
  // get data
  Uri uri = new Uri("https://...");
  response = await httpClient.GetAsync(uri);
  // display
  ... update the UI ...
}

最新更新