extend splash screen time till data get downloaded form server before application get started in windows phone 8 apps

StackOverflow https://stackoverflow.com/questions/22115667

Frage

actually i am creating windows phone 8 application .,

so my application initially need to download some files from the server before application being started( that means before application get started) ., so that i want to show splash screen till the files being downloaded from the server to my application local.,

i had a code to download file and i successfully know how to download like if the button was clicked in WP8.,

But i don't know how to automatically download a file before application being started.,

i had written downloading method in App.xaml.cs file and inside "void Application_Launching(object sender, LaunchingEventArgs e)" method to initially download files.,

But my problem is the splash screen normally dislayed over 2 or 3 seconds and my main page has been shown to user before my downloads complete.,

Here is my code for download in 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;
        }
    }

So my Question is :

1) is it right way to write code in App.xaml.cs file for download files from server before my application being shown to user ?

2) if it is wright way means " how to extend splash screen time till my file has been downloaded and before my application being shown to user "

someone please help me to solve.,

thanks in advance.,

War es hilfreich?

Lösung

The best suggestion to this is that you need to create a separate page for extended splash screen where splash screen with animations are shown while downloading the db takes places in another thread.

Extended splash screen is the answer for both of the questions.

Making the files download in App.xaml.cs causes the app to freeze leaves the user with nothing but to kill and it might not also not qualify the app certifications.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top