【问题标题】:Wp 8.1 app crashing when its not connected to debuggerWp 8.1 应用程序在未连接到调试器时崩溃
【发布时间】:2016-06-14 08:36:33
【问题描述】:

应用程序在连接到 PC 并使用调试器运行时工作。当我断开手机与 PC 的连接,从手机运行应用程序并尝试打开图库并将图像设置为图像控制时,问题就开始了。我试图在 try/catch 上的文件中写入错误,但从未调用过 catch,就像应用程序执行时没有错误一样。

这是我选择 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时,我打开图像编辑屏幕并运行此

 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);
            }

        }

就是这样,任何建议都值得赞赏;

【问题讨论】:

  • 到底哪里崩溃了?
  • 当我打开画廊并选择图像时,操作系统会写 Continue 。 . . (加载消息)然后应用崩溃
  • 总是崩溃还是随机?
  • 您对如何查看错误有什么建议吗?我已将电话上的语言更改为英语及其写作 Resuming 。 . .

标签: c# image crash windows-phone-8.1


【解决方案1】:

问题出在我的 MediaCapture 上。首先使用 mediaCapture.stopPreviewAsync();要停止预览,您必须释放 mediaCapture。 在调用 fileOpener 之前,请使用以下代码:

newCapture.Dispose();

【讨论】:

    【解决方案2】:

    为了捕获未处理的异常,您可以使用全局异常捕获器, 在 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 捕获很重要,例如 Corrupt State Exceptions: https://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035

    在这种情况下,您可以通过查看您的应用程序生成的 .dmp 文件来调试问题:{Phone}\Documents\Debug

    【讨论】:

    • 谢谢我会使用它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 2020-03-06
    相关资源
    最近更新 更多