Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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# 将App.xaml.cs的方法签名更改为返回异步任务<;布尔>;_C#_Silverlight_Windows Phone 8_Async Await_Task - Fatal编程技术网

C# 将App.xaml.cs的方法签名更改为返回异步任务<;布尔>;

C# 将App.xaml.cs的方法签名更改为返回异步任务<;布尔>;,c#,silverlight,windows-phone-8,async-await,task,C#,Silverlight,Windows Phone 8,Async Await,Task,我可以在App.xaml.cs中更改Inialization方法的方法签名吗 我试图让应用程序等待下载基本数据后再加载到下一个屏幕,但在使用Windows Phone Silverlight 8.0进行尝试时出错 这就是方法。它位于App.xaml.cs中,是应用程序启动时执行的方法 异步的普通签名。我添加了async这个词 签名已更改为我想要的: //应用程序启动时要执行的代码(例如,从开始) //重新激活应用程序时,此代码将不会执行 专用异步任务应用程序\u启动(对象发送方,启动事件参数e)

我可以在App.xaml.cs中更改Inialization方法的方法签名吗

我试图让应用程序等待下载基本数据后再加载到下一个屏幕,但在使用Windows Phone Silverlight 8.0进行尝试时出错

这就是方法。它位于App.xaml.cs中,是应用程序启动时执行的方法

异步的普通签名。我添加了async这个词

签名已更改为我想要的:

//应用程序启动时要执行的代码(例如,从开始)
//重新激活应用程序时,此代码将不会执行
专用异步任务应用程序\u启动(对象发送方,启动事件参数e)
{
Debug.WriteLine(“hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh;
Debug.WriteLine(“应用程序->启动->salvar_JSON”);
App.estativo=true;
尝试
{
Debug.WriteLine(“App->Launching->sevidorWeb->salvarJSON//tentiva”);
wait web.salvarJSON(ServidorWEB.URL_JSON_SLZ,ServidorWEB.ARQUIVO_JSON_SLZ);
wait web.salvarJSON(ServidorWEB.URL_JSON_ITZ,ServidorWEB.ARQUIVO_JSON_ITZ);
wait web.salvarJSON(ServidorWEB.URL_JSON_STI,ServidorWEB.ARQUIVO_JSON_STI);
等待sleepObj。将_设置为_NENHUM();
App.HOJE=等待节奏getDiaSemana();
等待节奏。INIIARELLOGIOINTERNO(网络);
返回true;
}
我怎么做

错误如下:


我同意库奇兹的建议

但是您仍然可以保持函数签名的原样,并使用Task.Run().Wait()机制

您可以将异步函数放在Run块中,并强制UI等待它退出


正如我所说,这不是一个好方法,我建议您显示一些加载屏幕,并将您的资源加载机制放在后面。

我同意KooKiz的建议

但是您仍然可以保持函数签名的原样,并使用Task.Run().Wait()机制

您可以将异步函数放在Run块中,并强制UI等待它退出


正如我所说,这不是一个好方法,建议显示一些加载屏幕,并将资源加载机制放在后面。

只有同步调用方法,才能在应用程序启动时进行下载,这会产生糟糕的用户体验(因为手机网络不稳定,所以下载可能需要很长时间)。只需将用户重定向到带有“加载”消息的自定义页面(基本上是一种splashscreen)并在您空闲时进行下载。或者更好的是,直接从需要的页面进行下载(使用进度指示器)只有同步调用方法,才能在应用程序启动时进行下载,这会产生糟糕的用户体验(因为手机网络不稳定,下载可能需要很长时间)。只需将用户重定向到带有“加载”消息的自定义页面(基本上是一种飞溅屏幕)在你空闲的时候下载。或者更好,直接从需要的页面下载(使用进度指示器)
    private async void Application_Launching(object sender, LaunchingEventArgs e)
    {
        Debug.WriteLine("hhhhhhhhhhhhhhhhhhhhhhhhhhhh");

        Debug.WriteLine("App-> Launching -> salvar_JSON");
        App.estaAtivo = true;
        try
        {
            Debug.WriteLine("App-> Launching -> sevidorWeb-> salvarJSON // Tentativa");
            await web.salvarJSON(ServidorWEB.URL_JSON_SLZ, ServidorWEB.ARQUIVO_JSON_SLZ);
            await web.salvarJSON(ServidorWEB.URL_JSON_ITZ, ServidorWEB.ARQUIVO_JSON_ITZ);
            await web.salvarJSON(ServidorWEB.URL_JSON_STI, ServidorWEB.ARQUIVO_JSON_STI);
            await sleepObj.set_to_NENHUM();
            App.HOJE = await tempo.getDiaSemana();
            await tempo.iniciarRelogioInterno(web);

        }
  // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private async Task<bool> Application_Launching(object sender, LaunchingEventArgs e)
        {
            Debug.WriteLine("hhhhhhhhhhhhhhhhhhhhhhhhhhhh");

            Debug.WriteLine("App-> Launching -> salvar_JSON");
            App.estaAtivo = true;
            try
            {
                Debug.WriteLine("App-> Launching -> sevidorWeb-> salvarJSON // Tentativa");
                await web.salvarJSON(ServidorWEB.URL_JSON_SLZ, ServidorWEB.ARQUIVO_JSON_SLZ);
                await web.salvarJSON(ServidorWEB.URL_JSON_ITZ, ServidorWEB.ARQUIVO_JSON_ITZ);
                await web.salvarJSON(ServidorWEB.URL_JSON_STI, ServidorWEB.ARQUIVO_JSON_STI);
                await sleepObj.set_to_NENHUM();
                App.HOJE = await tempo.getDiaSemana();
                await tempo.iniciarRelogioInterno(web);
                return true;
            }