在Application_Launching中加载Web数据 [英] Loading Web Data in Application_Launching

查看:50
本文介绍了在Application_Launching中加载Web数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,

我正在编写一个可从网络加载一些初始数据的应用.

I'm writing an app that load some initial data from the web.

我要执行的操作是先让此数据加载到Application_Launching中,然后再让应用继续执行MainPage.xaml.

What I'm trying to do is to load this data in Application_Launching before I let the app proceed to MainPage.xaml.

有两个原因:

There are two reasons for this:

       将数据保留在App.xaml中,以便在调用Application_Deactivated时我可以将数据保存到隔离存储中,并在调用Application_Activated时将其加载回去.

1.       To keep the data in App.xaml so that when Application_Deactivated gets called I can save the data to isolated storage and load it back when Application_Activated gets called.

       另一个原因是保持启动屏幕直到数据为网络加载.

2.       The other reason is to keep the splash screen up until the data is loaded for the web.

我尝试将发起Web请求的呼叫放在单独的线程中,并等待线程完成,但是 那没有用.似乎网络调用被放在主UI线程上.

I’ve tried putting my call that initiates the web request in a separate thread, and waiting until thread is done, but that didn’t work. It appears that network calls get put on the main UI thread.

有人有什么想法吗?还是做我想完成的更好的方法?

加载内容如下:


protected void LoadRSS(string uri)
{
    WebClient wc = new WebClient();
    wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
    Uri feedUri = new Uri(uri, UriKind.Absolute);
    wc.OpenReadAsync(feedUri);
}

private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
  .....
}

推荐答案

 

您可以不使用后台工作者吗?

Could you not use a background worker?

 

您可以在初始屏幕上更新状态,然后以完成的方法打开主窗口?

You can update status on your splashscreen and then in the completed method you could open your mainwindow?


这篇关于在Application_Launching中加载Web数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆