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.,