Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.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# 如何在UWP中的OnLaunchApplicationAsync for Prism中实现耗时任务?_C#_.net_Win Universal App_Windows 10_Prism - Fatal编程技术网

C# 如何在UWP中的OnLaunchApplicationAsync for Prism中实现耗时任务?

C# 如何在UWP中的OnLaunchApplicationAsync for Prism中实现耗时任务?,c#,.net,win-universal-app,windows-10,prism,C#,.net,Win Universal App,Windows 10,Prism,我正在使用Prism开发UWP,当应用程序启动时,它需要将一个文件从InstallLocation复制到LocalFolder,并确保该文件存在于LocalFolder中,然后再导航到MainPage。你知道我怎样才能做到吗 看起来OnLaunchApplicationAsync可以返回任务,但它在任务完成之前首先导航到主页 protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args) {

我正在使用Prism开发UWP,当应用程序启动时,它需要将一个文件从InstallLocation复制到LocalFolder,并确保该文件存在于LocalFolder中,然后再导航到MainPage。你知道我怎样才能做到吗

看起来OnLaunchApplicationAsync可以返回任务,但它在任务完成之前首先导航到主页

protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
    {
        Task task = new Task(async () =>
        {
            StorageFile dataFile = await Package.Current.InstalledLocation.GetFileAsync("xx.db3");
            await dataFile.CopyAsync(ApplicationData.Current.LocalFolder, "xx.db3", NameCollisionOption.FailIfExists);
        });

        NavigationService.Navigate("Main", null);
        Window.Current.Activate();

        return task;

        //return Task.FromResult<object>(null);
    }
protectedoverride Task OnLaunchApplicationAsync(启动ActivatedEventargs args)
{
任务=新任务(异步()=>
{
StorageFile dataFile=await Package.Current.InstalledLocation.GetFileAsync(“xx.db3”);
等待dataFile.CopySync(ApplicationData.Current.LocalFolder,“xx.db3”,NameCollisionOption.FailIfExists);
});
NavigationService.Navigate(“主”,空);
Window.Current.Activate();
返回任务;
//返回Task.FromResult(空);
}
感谢您的帮助。

这个怎么样

protected override async Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
    StorageFile dataFile = await Package.Current.InstalledLocation.GetFileAsync("xx.db3");
    await dataFile.CopyAsync(ApplicationData.Current.LocalFolder, "xx.db3", NameCollisionOption.FailIfExists);

    NavigationService.Navigate("Main", null);
    Window.Current.Activate();
}

无需将事情过分复杂化:-)

您需要等待完成后续任务。