run WebClient.DownloadStringCompleted before loading MainPage_Loaded in silverlight [closed]
I开发者_如何学运维 want to load this event handler before MainPage_Loaded
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("./ImageList.xml", UriKind.Relative));
void wc_DownloadStringCompleted(object sender,
System.Net.DownloadStringCompletedEventArgs e){.....}
I think this was the question
I want to "load some resources" "Asynchronously" before loading the MainPage!
WebClient wc = new WebClient();
wc.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("./ImageList.xml", UriKind.Relative));
void wc_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e){.....}
Answer
If it is the main page of your application so you can add this code to "app.xaml.cs" in Application_Startup event handler. note that since you are loading the resource asynchronously then you should load the main page in your event handler not Application_Startup unless you don’t care if the Main page got loaded before completion of the resource loading process.
精彩评论