iOS在执行过程中丢弃任务

本文关键字:任务 过程中 执行 iOS | 更新日期: 2023-09-27 17:55:06

某些东西使我的运行任务超出了代码中的某个点(见下文)。它只是停止执行。这只会发生在iOS设备上。在iOS模拟器和android设备上,它运行得非常完美。有人见过这样的东西吗?我不认为这是死锁或竞争条件,因为那样它就不能在其他设备上成功完成,对吧?

下面是一些代码;

private async Task ExecuteFreshAndPopulateUI(IFetchVehicleCommand command)
{
    List<Models.Vehicle.Vehicle> vehicles = await command.ReturnAndExecute<Models.Vehicle.Vehicle>();
    var z = 9;
    ListPopulateObservableCollection(vehicles, view.Vehicles);
}
public virtual async Task<dynamic> ReturnAndExecute<T>() where T : new()
{
    await FlushCache<T>();
    await Execute();
    await CheckIfCached<T>();
    return (dynamic) cachedResult.cachedObject;
}
public override async Task Execute()
{
    try
    {
        dynamic x = await fetchableService.Fetch(userId);
        if (x != null)
        {
            await cacheProvider.Cache(x); // THIS is the last line to be called from this method, it never returns
            SetCached(true);
        }
    }
    catch (Exception ex)
    {
        AddValidationError(ex.Message);
    }
}
public async Task Cache(dynamic obj)
{
    await database.InsertAllAsync((IEnumerable)obj); // this runs
} // this is the last breakpoint to be hit

编辑:减少代码,使问题更清楚。

iOS在执行过程中丢弃任务

这可能是iOS设备在动态支持方面的已知限制造成的问题。Xamarin的信息在这里和一个线程在这里(但你可以从线程的最后一篇文章中看到,一些动态支持可能是可用的)。

这个问题的棘手之处在于,动态代码在iOS模拟器上运行良好(因为mac支持JIT),但在iOS设备上就会失败(因为iOS设备硬件已经明确禁用了JIT)。

我有一个部分解决方案。移除等待等待cacheProvider.Cache (x);使其返回到Execute方法,操作能够成功完成。这是部分的,因为它只在调试时工作,当我在临时配置中通过CI运行它时,它仍然没有完成。