C# 如何在UWP中的OnLaunchApplicationAsync for Prism中实现耗时任务?
我正在使用Prism开发UWP,当应用程序启动时,它需要将一个文件从InstallLocation复制到LocalFolder,并确保该文件存在于LocalFolder中,然后再导航到MainPage。你知道我怎样才能做到吗 看起来OnLaunchApplicationAsync可以返回任务,但它在任务完成之前首先导航到主页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) {
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();
}
无需将事情过分复杂化:-)您需要等待完成后续任务。