[英]ContinuationManager resuming freezing WP8.1
I am using PickSingleFileAndContinue() method to pick the picture and resuming to my app. 我正在使用PickSingleFileAndContinue()方法来选择图片并恢复到我的应用程序。 In overrided OnActivated() I call RestoreAsync() and after that calling ContinueFileOpenPicker() from ContinuationManager class:
在重写的OnActivated()中,我调用RestoreAsync(),然后从ContinuationManager类中调用ContinueFileOpenPicker():
var settingsPage = SimpleIoc.Default.GetInstance<SettingsViewModel>();
if (settingsPage != null && args is FileOpenPickerContinuationEventArgs)
{
settingsPage.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs);
}
To debug app I am using information from this page: https://msdn.microsoft.com/en-us/library/dn631755.aspx 要调试应用程序,我正在使用此页面上的信息: https : //msdn.microsoft.com/zh-cn/library/dn631755.aspx
After picking image from provider, application successfully calling ContinueFileOpenPicker with right arguments with StorageFile object, when I am continue to step over by step, at the and of last method at the constructor of the ViewModel I cannot continue to debug, because the app and sometimes VS2013 freezing. 从提供程序中选择图像后,应用程序成功地调用了带有StorageFile对象的带有正确参数的ContinueFileOpenPicker,当我继续逐步操作时,在ViewModel的构造函数的and方法的最后,我无法继续调试,因为该应用程序有时VS2013冻结。 I can hold back and Swipe-down app, but whatever need to waiting for app.
我可以保留和向下滑动应用程序,但是需要等待应用程序。 After that, app is crashing.
在那之后,应用程序崩溃了。 Please, I cannot catch exception... Help.
拜托,我无法捕捉到异常...帮助。 :(
:(
Your SettingsViewModel
should inherit IFileOpenPickerContinuable
, 您的
SettingsViewModel
应该继承IFileOpenPickerContinuable
,
public class SettingsViewModel : Screen, IFileOpenPickerContinuable
Frames are in some cases associated with the View not the ViewModel. 在某些情况下,框架与视图关联,而不与ViewModel关联。 Thus you should add a custom method for this to work:
因此,您应该为此添加一个自定义方法:
Add in ContinuationManager.cs 添加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;
}
}
Ensure that the SettingsViewModel that is returned from 确保从返回的SettingsViewModel
var settingsPage = SimpleIoc.Default.GetInstance<SettingsViewModel>();
is the same instance that called PickSingleFileAndContinue
, otherwise it will not work, it will keep on suspending and waiting for something to return control. 与名为
PickSingleFileAndContinue
实例相同 ,否则它将无法正常工作,它将继续挂起并等待返回控制的内容。
Then in App.xaml.cs you can add: 然后在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?
但是我应该从OnLaunched重复代码吗?
No, only the OnActivate code should be called, the rest should stay as is (but you could do whatever you want) 不,仅应调用OnActivate代码,其余应保持原样(但您可以做任何想做的事情)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.