延长启动屏幕的时间,直到数据获取下载表格服务器之前,应用程序开始在Windows Phone 8应用程序

问题描述:

其实我正在创建Windows Phone 8应用程序。 (这意味着应用程序开始之前),以便我想显示启动画面,直到文件从服务器下载到我的应用程序本地。,延长启动屏幕的时间,直到数据获取下载表格服务器之前,应用程序开始在Windows Phone 8应用程序

我有一个代码来下载文件,我成功了解如何下载就像在WP8中点击按钮一样,

但是我不' t知道如何在应用程序启动之前自动下载文件,

我已经在App.xaml.cs文件中写入了下载方法,并在“void Application_Launching(object sender,LaunchingEventArgs e)”方法中初始下载文件。

但我的问题是闪屏通常dislayed超过2到3秒钟之前我下载完成我的主页已经显示出用户,

这里是我的代码下载在App.xaml.cs

 private void Application_Launching(object sender, LaunchingEventArgs e) 
    { 
     downloadDBFile(); 
    } 
    public enum DownloadStatus { Ok, Error, fileExist }; 

    public static async Task<DownloadStatus> DownloadFileSimle(Uri fileAdress, string fileName) 
    { 
     try 
     { 
      WebRequest request = WebRequest.Create(fileAdress); 
      if (request != null) 
      { 
       WebResponse response2 = await request.GetResponseAsync(); 
       using (Stream resopnse = response2.GetResponseStream()) 
       { 
        using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication()) 
        { 
         if (ISF.FileExists(fileName)) 
          ISF.DeleteFile(fileName); 
         using (IsolatedStorageFileStream file = ISF.CreateFile(fileName)) 
         { 
          const int BUFFER_SIZE = 10 * 1024; 
          byte[] buf = new byte[BUFFER_SIZE]; 

          int bytesread = 0; 
          while ((bytesread = await resopnse.ReadAsync(buf, 0, BUFFER_SIZE)) > 0) 
           file.Write(buf, 0, bytesread); 
         } 
        } 
        return DownloadStatus.Ok; 
       } 
      } 
      return DownloadStatus.Error; 
     } 
     catch { return DownloadStatus.Error; } 
    } 
    public async void downloadDBFile() 
    { 
     DownloadStatus fileDownloaded = await DownloadFileSimle(new Uri(@"https://dl.dropboxusercontent.com/s/nz9107khswqttyp/sample.sqlite?dl=1&token_hash=AAE7EOhKzpVlAbCUlgwToURZOg0xZzMesu_gPTcLceZzDg", UriKind.Absolute), "sample.sqlite"); 
     switch (fileDownloaded) 
     { 
      case DownloadStatus.Ok: 
       MessageBox.Show(fileDownloaded.ToString()); 
       break; 
      case DownloadStatus.Error: 
       MessageBox.Show(fileDownloaded.ToString()); 
       break; 
      case DownloadStatus.fileExist: 
       MessageBox.Show(fileDownloaded.ToString()); 
       break; 
      default: 
       MessageBox.Show("There was an error while downloading."); 
       break; 
     } 
    } 

所以我的问题是:

1)是否正确的方式来编写App.xaml.cs文件中的代码从服务器下载文件之前,我的应用程序显示给用户?

2)如果是赖特韦意思是“如何直到我的文件已经下载并延长闪屏时间我的应用程序被显示给用户之前”

有人请帮我解决,

提前致谢,

最好的建议是,你需要为扩展启动画面创建一个单独的页面,其中显示启动画面动画时下载数据库在另一个线程中。

Extended splash screen是两个问题的答案。

在App.xaml.cs中下载文件会导致应用程序冻结,导致用户只能杀死它,并且可能不会限制应用程序认证。

+0

k我试着根据你的建议创建新的页面来扩展初始屏幕,它对我来说工作正常。谢谢你最大限度地回复我,谢谢堆栈溢出。 –