Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Xamarin.C表单中检查长时间下载的数据#_C#_Xamarin.forms_Timer_Download Manager - Fatal编程技术网

C# 如何在Xamarin.C表单中检查长时间下载的数据#

C# 如何在Xamarin.C表单中检查长时间下载的数据#,c#,xamarin.forms,timer,download-manager,C#,Xamarin.forms,Timer,Download Manager,我正在进行一项任务,在下载数据时,我们会在用户手机上显示ActivityIndicator。现在,当后台下载正在运行时,当前ActivityIndicator显示一个标签“正在加载…”。但如果下载时间超过20秒,我需要将标签从“加载…”更新为类似“仍在下载…” 我想知道如何使用C#中的计时器功能来检查我的下载是否已经运行了20秒。据我所知,OnTimedEvent()只在设定的时间过后才会触发,但我需要并行执行下载过程。下面是我正在努力实现的目标 SetTimer(20000, "Still D

我正在进行一项任务,在下载数据时,我们会在用户手机上显示ActivityIndicator。现在,当后台下载正在运行时,当前ActivityIndicator显示一个标签“正在加载…”。但如果下载时间超过20秒,我需要将标签从“加载…”更新为类似“仍在下载…”

我想知道如何使用C#中的计时器功能来检查我的下载是否已经运行了20秒。据我所知,OnTimedEvent()只在设定的时间过后才会触发,但我需要并行执行下载过程。下面是我正在努力实现的目标

SetTimer(20000, "Still Downloading...")
// Here while the below api call is running, if it takes more than 20 seconds to complete then fire up the event to update the loading label. 
var response = obj.GetFileData(JsonConvert.SerializeObject(inputJson)); 
下面是我从中读取的计时器功能

我不确定我在这里使用timer类的方法是否正确。我遇到过多篇关于timer类的帖子,但是他们都在谈论在计时器过期时触发事件,但没有谈论与api调用并行运行计时器


任何帮助都将不胜感激

您的意思是标签文本没有从“加载…”更新到“仍在下载…”更新吗

我认为当您启动
OnTimedEvent
时,它可能不在主线程(UIThread)中,因此
mylabel.text=eventMessage将无法按预期工作

尝试在主线程中运行,如:

public  void OnTimedEvent(string eventMessage)
    {
        Device.BeginInvokeOnMainThread(() => { mylabel.Text = eventMessage; });
    }

这行吗?我看不出有什么明显的问题
public  void OnTimedEvent(string eventMessage)
    {
        Device.BeginInvokeOnMainThread(() => { mylabel.Text = eventMessage; });
    }