Wp 8.1 应用程序在未连接到调试器时崩溃
Wp 8.1 app crashing when its not connected to debugger
应用程序在连接到 PC 并且 运行 使用调试器时工作。当我断开 phone 与 PC 的连接,运行 应用程序与 phone 的连接并尝试打开图库并将图像设置为图像控件时,问题就开始了。我试图在 try/catch 上的文件中写入错误,但从未调用 catch,就像应用程序执行时没有错误一样。
这是我 select img:
的代码
private async void galleryBtn_Click(object sender, RoutedEventArgs e)
{
try
{
FileOpenPicker filePicker = new FileOpenPicker();
filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
filePicker.ViewMode = PickerViewMode.Thumbnail;
// Filter to include a sample subset of file types
filePicker.FileTypeFilter.Clear();
filePicker.FileTypeFilter.Add(".bmp");
filePicker.FileTypeFilter.Add(".png");
filePicker.FileTypeFilter.Add(".jpeg");
filePicker.FileTypeFilter.Add(".jpg");
filePicker.PickSingleFileAndContinue();
view.Activated += viewActivated;
}
catch (Exception err)
{
string error = err.StackTrace.ToString();
await saveStringToLocalFile("test11", error);
}
}
比它去:
private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
{
try
{
FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;
if (args != null)
{
if (args.Files.Count == 0) return;
view.Activated -= viewActivated;
StorageFile storageFile = args.Files[0];
var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
await bitmapImage.SetSourceAsync(stream);
var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
var obj = App.Current as App;
obj.ImageToEdit = bitmapImage;
obj.fileTransfer = storageFile;
checkTorch = -1;
await newCapture.StopPreviewAsync();
Frame.Navigate(typeof(EditImage));
}
}
catch (Exception err) {
string error = err.StackTrace.ToString();
await saveStringToLocalFile("test11", error);
}
}
当 img selected 我打开屏幕进行图像编辑和 运行 这个
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
try
{
var obj = App.Current as App;
slika = obj.ImageToEdit;
original = obj.ImageToEdit;
ImagePreview.Source = slika;
RotateTransform myRotateTransform = new RotateTransform();
myRotateTransform.Angle = 0;
ImagePreview.RenderTransform = myRotateTransform;
var localSettings = ApplicationData.Current.LocalSettings;
}
catch (Exception err)
{
string error = err.StackTrace.ToString();
await saveStringToLocalFile("test11", error);
}
}
仅此而已,欢迎任何建议;
问题出在我的 MediaCapture 上。首先使用mediaCapture.stopPreviewAsync();停止预览,然后您必须释放 mediaCapture。
在调用 fileOpener 之前使用此代码:
newCapture.Dispose();
为了捕获未处理的异常,您可以使用全局异常捕获器,
在 App.xaml.cs 文件中定义:
public App()
{
this.InitializeComponent();
this.Suspending += this.OnSuspending;
this.UnhandledException += UnhandledExceptionHandler;
}
private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
log.Critical(e.Exception);
}
重要的是要了解并非所有异常都可以使用 try\catch 捕获,例如损坏状态异常:
https://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035
在这种情况下,您可以通过查看您的应用程序生成的 .dmp 文件来调试问题:{Phone}\Documents\Debug
应用程序在连接到 PC 并且 运行 使用调试器时工作。当我断开 phone 与 PC 的连接,运行 应用程序与 phone 的连接并尝试打开图库并将图像设置为图像控件时,问题就开始了。我试图在 try/catch 上的文件中写入错误,但从未调用 catch,就像应用程序执行时没有错误一样。
这是我 select img:
的代码private async void galleryBtn_Click(object sender, RoutedEventArgs e)
{
try
{
FileOpenPicker filePicker = new FileOpenPicker();
filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
filePicker.ViewMode = PickerViewMode.Thumbnail;
// Filter to include a sample subset of file types
filePicker.FileTypeFilter.Clear();
filePicker.FileTypeFilter.Add(".bmp");
filePicker.FileTypeFilter.Add(".png");
filePicker.FileTypeFilter.Add(".jpeg");
filePicker.FileTypeFilter.Add(".jpg");
filePicker.PickSingleFileAndContinue();
view.Activated += viewActivated;
}
catch (Exception err)
{
string error = err.StackTrace.ToString();
await saveStringToLocalFile("test11", error);
}
}
比它去:
private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
{
try
{
FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;
if (args != null)
{
if (args.Files.Count == 0) return;
view.Activated -= viewActivated;
StorageFile storageFile = args.Files[0];
var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
await bitmapImage.SetSourceAsync(stream);
var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
var obj = App.Current as App;
obj.ImageToEdit = bitmapImage;
obj.fileTransfer = storageFile;
checkTorch = -1;
await newCapture.StopPreviewAsync();
Frame.Navigate(typeof(EditImage));
}
}
catch (Exception err) {
string error = err.StackTrace.ToString();
await saveStringToLocalFile("test11", error);
}
}
当 img selected 我打开屏幕进行图像编辑和 运行 这个
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
try
{
var obj = App.Current as App;
slika = obj.ImageToEdit;
original = obj.ImageToEdit;
ImagePreview.Source = slika;
RotateTransform myRotateTransform = new RotateTransform();
myRotateTransform.Angle = 0;
ImagePreview.RenderTransform = myRotateTransform;
var localSettings = ApplicationData.Current.LocalSettings;
}
catch (Exception err)
{
string error = err.StackTrace.ToString();
await saveStringToLocalFile("test11", error);
}
}
仅此而已,欢迎任何建议;
问题出在我的 MediaCapture 上。首先使用mediaCapture.stopPreviewAsync();停止预览,然后您必须释放 mediaCapture。 在调用 fileOpener 之前使用此代码:
newCapture.Dispose();
为了捕获未处理的异常,您可以使用全局异常捕获器, 在 App.xaml.cs 文件中定义:
public App()
{
this.InitializeComponent();
this.Suspending += this.OnSuspending;
this.UnhandledException += UnhandledExceptionHandler;
}
private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
log.Critical(e.Exception);
}
重要的是要了解并非所有异常都可以使用 try\catch 捕获,例如损坏状态异常: https://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035
在这种情况下,您可以通过查看您的应用程序生成的 .dmp 文件来调试问题:{Phone}\Documents\Debug