gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:47:24 25 4
gpt4 key购买 nike

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

看起来 OnLaunchApplicationAsync 可以返回一个任务,但它在任务完成之前先导航到 MainPage。

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);
}

感谢任何帮助。

最佳答案

这个呢?

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();
}

不需要把事情搞得太复杂 :-)

关于c# - 我如何在 UWP 中的 OnLaunchApplicationAsync for Prism 中实现耗时任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36824374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com