ContinuationManager 恢复冻结 WP8.1

ContinuationManager resuming freezing WP8.1

我正在使用 PickSingleFileAndContinue() 方法来选择图片并恢复到我的应用程序。在覆盖的 OnActivated() 中,我调用 RestoreAsync() ,然后从 ContinuationManager class:

调用 ContinueFileOpenPicker()
var settingsPage = SimpleIoc.Default.GetInstance<SettingsViewModel>();
if (settingsPage != null && args is FileOpenPickerContinuationEventArgs)
 {
  settingsPage.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs);
 }

为了调试应用程序,我使用了此页面中的信息:https://msdn.microsoft.com/en-us/library/dn631755.aspx

从提供程序中选取图像后,应用程序成功调用 ContinueFileOpenPicker 并使用 StorageFile 对象的正确参数,当我继续一步步进行时,在 ViewModel 构造函数的最后一个方法中我无法继续调试,因为app有时VS2013卡顿。我可以阻止并向下滑动应用程序,但无论如何都需要等待应用程序。之后,应用程序崩溃了。拜托,我无法捕捉到异常......帮助。 :(

你的 SettingsViewModel 应该继承 IFileOpenPickerContinuable,

public class SettingsViewModel : Screen, IFileOpenPickerContinuable

在某些情况下,框架与 View 而不是 ViewModel 相关联。 因此,您应该为此添加一个自定义方法:

加入ContinuationManager.cs

internal void Continue(IContinuationActivatedEventArgs args, IFileOpenPickerContinuable filepickerPage)
{
    if (args == null)
        throw new ArgumentNullException("args");

    if (this.args != null && !handled)
        throw new InvalidOperationException("Can't set args more than once");

    this.args = args;
    this.handled = false;
    this.id = Guid.NewGuid();

    if (wabPage == null)
        return;

    switch (args.Kind)
    {
        case ActivationKind.PickFileContinuation:
            if (filepickerPage != null)
            {
                filepickerPage.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs);
            }
            break;

        case ActivationKind.PickSaveFileContinuation:
            break;

        case ActivationKind.PickFolderContinuation:
            break;

        case ActivationKind.WebAuthenticationBrokerContinuation:
            break;
    }
}

确保return来自

的 SettingsViewModel
var settingsPage = SimpleIoc.Default.GetInstance<SettingsViewModel>();

是调用PickSingleFileAndContinue同一个实例,否则将无法工作,它会一直挂起等待return控制。

然后在App.xaml.cs中你可以添加:

 protected override void OnActivated(IActivatedEventArgs e)
 {
      base.OnActivated(e);
      // Add all of the Frame code

      var continuationEventArgs = e as IContinuationActivatedEventArgs;
      continuationManager = new ContinuationManager();
      SettingsViewModel settingsPage = SimpleIoc.Default.GetInstance<SettingsViewModel>();

      if (continuationEventArgs != null)
      {
          continuationManager.Continue(continuationEventArgs, settingsPage);
      }
  }

But should I repeat code from OnLaunched?

不,应该只调用 OnActivate 代码,其余的应该保持原样(但你可以做任何你想做的事)