2016-10-15 18 views
2

我正在使用Cirrious.MvvmCross.Plugins.PictureChooser在Android Xamarin平臺上拍照。 但是,當我從畫面取消而不是拍照時,顯示如下所示 enter image description here如何解決Xamarin中TakePicture的SyncContext.cs問題?

而我的應用程序崩潰。 這是我的代碼片段。

CameraViewmodel.cs 
... 
public System.Windows.Input.ICommand TakePictureCommand 
{ 
get { return (_takePictureCommand = _takePictureCommand ?? new MvxCommand(() => TakePictureAsync())); } 
} 
... 

    private async void TakePictureAsync() 
    { 
     try 
     { 
     var stream = await _pictureChooserTask.TakePictureAsync(400, 95); 
     var memoryStream = new MemoryStream(); 
     await stream.CopyToAsync(memoryStream); 
     ... 
     //Add to view model 
     CameraImageViewModel imageViewModel = new CameraImageViewModel(image, this); 
     RaisePropertyChanged(() => HasPhotoBeenTaken); 
     RaisePropertyChanged(() => CommentHintText); 
     } 
     catch (Exception ex) 
     { 
     throw new Exception(ex.Message); 
     } 
    } 

有沒有辦法解決這個問題?

回答

3

這是失敗的,因爲你的async void方法拋出一個異常。您需要查明實際情況,並解決根本問題。您可以通過在throw new Exception行放置一個斷點來找出異常情況。

爲防止Visual Studio啓動此對話框,請在調試器設置下啓用「Just My Code」。