开拓者字段为空

时间:2020-08-15 19:43:25

标签: c# asp.net asp.net-core blazor

我有这样的代码: 这只是每秒更新div的简单方法:

<div style="font-size:50px">@dailyCases.ToString("0,0.00")</div>

@code
{
private double dailyCases;
private bool needsUpdate = false;
private CovidDataManager covidManager;

protected async override Task OnInitializedAsync()
{
    Console.WriteLine("init");
    dailyCases = await updateData();
    await StartCounter();
}

private Task StartCounter()
{
    var timer = new System.Timers.Timer(1000);
    timer.Elapsed += async (sender, e) =>
    {
        dailyCases = await update();
        await InvokeAsync(StateHasChanged);
    };

    timer.Start();
    return Task.CompletedTask;
}

private async Task<double> updateData()
{
    var httpResponse = await covidRepository.GetYesterdayData("FRANCE");
    var covidDailyInfoDTO = mapper.Map<Covid19Portal.Shared.DTO.CovidDailyInfoDTO>(httpResponse.Response);
    var covidManager = new Covid19Portal.Shared.CovidDataManager(covidDailyInfoDTO);
    return await Task.FromResult(covidManager.SickUpToNow);
}

private async Task<double> update()
{
    return await Task.FromResult(covidManager.SickUpToNow);
    //return await Task.FromResult(covidManager.SickUpToNow);
}

}

我得到错误,并且在调用更新后covidManager为null。 知道为什么吗?

0 个答案:

没有答案