C# 在OnAppearing函数上添加延迟
我想在检查设备的internet连接之前添加延迟。我有一个功能。当页面仅在X秒后出现时,我的应用程序将检查设备的互联网连接 我有两个问题: 1.我怎样才能增加延迟? 2.如果我添加延迟,我的页面是否会在延迟开始前首先显示,或者我的页面仅在延迟后显示C# 在OnAppearing函数上添加延迟,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我想在检查设备的internet连接之前添加延迟。我有一个功能。当页面仅在X秒后出现时,我的应用程序将检查设备的互联网连接 我有两个问题: 1.我怎样才能增加延迟? 2.如果我添加延迟,我的页面是否会在延迟开始前首先显示,或者我的页面仅在延迟后显示 protected async override void OnAppearing() { base.OnAppearing(); //Add delay before executing the code below if
protected async override void OnAppearing()
{
base.OnAppearing();
//Add delay before executing the code below
if (CrossConnectivity.Current.IsConnected){
//Some code here
}
}
使用fire and forget任务,您的页面将继续加载/显示
protected async override void OnAppearing()
{
base.OnAppearing();
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(10));
if (CrossConnectivity.Current.IsConnected)
{
//Some code here
Device.BeginInvokeOnMainThread(() =>
{
// If you need to update an UI element
});
}
});
}
在调用函数之前,我的页面是否会首先显示,或者页面仅在延迟完成后才会显示?它不起作用,并且当我尝试导航到其他页面时,没有显示任何内容编辑正在不同的线程中运行,因此这两个线程同时运行,假设延迟足够长,页面将首先显示。我的导航。当我导航到我的页面时,我的所有页面都有延迟now@LawrenceAgulto ? 你是说你在每次出现时都增加了延迟?我怎么做?