我已将 BugSense 添加到我的 Windows Phone 应用程序并相应地修改了 app.xaml.cs。但是,我知道有些用户遇到了崩溃,但 BugSense 没有看到它。BugSense 可以查看新会话和其他内容,因此我知道许可证是正确的。
我相信崩溃发生在这段代码中,尤其是我认为的 webclient。我可以在此代码中添加什么,以便在发生某些事情时,BugSense 会报告它?
private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector selector = sender as LongListSelector;
// verifying our sender is actually a LongListSelector
if (selector == null)
return;
SoundData data = selector.SelectedItem as SoundData;
// verifying our sender is actually SoundData
if (data == null)
return;
if (data.IsDownloaded)
{
this.PlaySound(IsolatedStorageFile.GetUserStoreForApplication().OpenFile(data.SavePath, FileMode.Open, FileAccess.Read, FileShare.Read));
}
else
{
if (!SimpleIoc.Default.GetInstance<INetworkService>().IsConnectionAvailable)
{
MessageBox.Show("You need an internet connection to download this sound.");
}
else
{
WebClient client = new WebClient();
client.DownloadProgressChanged += (senderClient, args) =>
{
Dispatcher.BeginInvoke(() =>
{
data.DownloadProgress = args.ProgressPercentage;
});
};
client.OpenReadCompleted += (senderClient, args) =>
{
using (IsolatedStorageFileStream fileStream = IsolatedStorageFile.GetUserStoreForApplication().CreateFile(data.SavePath))
{
args.Result.Seek(0, SeekOrigin.Begin);
args.Result.CopyTo(fileStream);
this.PlaySound(fileStream);
data.Status = DownloadStatus.Downloaded;
}
args.Result.Close();
};
client.OpenReadAsync(new Uri(data.FilePath));
data.Status = DownloadStatus.Downloading;
}
}
selector.SelectedItem = null;
}