我的应用程序在调试版本中表现良好,但当我将发布版本作为测试版本上传到商店时非常缓慢,我认为这可能是因为sqlite。我使用的是SQLite.WP80, Version=3.8.4.3
,这是我的代码
using (var db = new SQLite.SQLiteConnection(App.DBPath))
{
verses = db.Table<schools>().ToList();
}
对我来说似乎很奇怪,因为调试版本的性能很好
p。该应用程序是为Windows phone 8开发的,但我的设备破坏了8.1开发者预览
我将使用异步方法获取数据。它将使应用程序感觉更灵敏
using (var db = new SQLite.SQLiteConnection(App.DBPath))
{
verses = await db.Table<schools>().ToListAsync();
}
问题是由于数据库的位置,起初我只是将它添加到我的资产文件中并直接从那里访问它,当我使用visual studio将我的设备推到设备时,这是可以的但是当我把它作为测试版上传到商店时,它的性能非常非常差
解决方案:我添加了一个片段,首先将其复制到隔离的存储文件夹中,应用程序正常
private void CopyDatabase()
{
IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication();
String DBFile = "CountryDB.sqlite";
if (!ISF.FileExists(DBFile)) CopyFromContentToStorage(ISF, "Assets/CountryDB.sqlite", DBFile);
}
private void CopyFromContentToStorage(IsolatedStorageFile ISF, String SourceFile, String DestinationFile)
{
Stream Stream = Application.GetResourceStream(new Uri(SourceFile, UriKind.Relative)).Stream;
IsolatedStorageFileStream ISFS = new IsolatedStorageFileStream(DestinationFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, ISF);
CopyStream(Stream, ISFS);
ISFS.Flush();
ISFS.Close();
Stream.Close();
ISFS.Dispose();
}
private void CopyStream(Stream Input, IsolatedStorageFileStream Output)
{
Byte[] Buffer = new Byte[5120];
Int32 ReadCount = Input.Read(Buffer, 0, Buffer.Length);
while (ReadCount > 0)
{
Output.Write(Buffer, 0, ReadCount);
ReadCount = Input.Read(Buffer, 0, Buffer.Length);
}
}