简体   繁体   English

在Windows Phone 8-模拟器中实施试用版时出错

[英]Error implementing trial in Windows Phone 8 - Emulator

This is the error message. 这是错误消息。

An exception of type 'System.InvalidOperationException' occurred in System.Windows.ni.dll but was not handled in user code Additional information: Error displaying MessageBox. System.Windows.ni.dll中发生类型'System.InvalidOperationException'的异常,但未在用户代码中处理。其他信息:显示MessageBox时出错。 The most common reason is attempting to call Show while an application is launching or being activated. 最常见的原因是在启动或激活应用程序时尝试调用Show。 Wait for page navigation events before calling Show. 等待页面导航事件,然后再调用Show。

It happens right at the beginning when the app is launching and stopped at this function in the first if statement when trying to show the message box. 它会在应用程序启动时一开始就发生,并在尝试显示消息框时在第一个if语句中的此功能处停止。

Code source = How to implement a trial experience in a Windows Phone app 代码源= 如何在Windows Phone应用中实现试用体验

    private void CheckLicense()
    {
        // this displays a dialog so that we can simulate trial mode being on or off. 
#if DEBUG
        string message = "Press 'OK' to simulate trial mode. Press 'Cancel' to run the application in normal mode.";
        if (MessageBox.Show(message, "Debug Trial",
             MessageBoxButton.OKCancel) == MessageBoxResult.OK)
        {
            _isTrial = true;
        }
        else
        {
            _isTrial = false;
        }
#else
        _isTrial = _licenseInfo.IsTrial();
#endif
    }

As the error indicates it is not possible to show the message box before the first page navigation. 如错误所示,无法在首页导航之前显示消息框。

MSDN has a sample specific for trial experience on Windows Phone 8 . MSDN有一个特定于Windows Phone 8的试用体验的示例。 It's authored by the Windows Phone team, and it does not have any message boxes in the initialization code. 它是由Windows Phone团队创作的,并且初始化代码中没有任何消息框。

I had the same issue. 我遇到过同样的问题。 Here's the solution. 这是解决方案。 You need to enclose your message box within [Deployment.Current.Dispatcher.BeginInvoke] For example: 您需要将消息框放在[Deployment.Current.Dispatcher.BeginInvoke]中,例如:

Deployment.Current.Dispatcher.BeginInvoke(() =>
    {
        MessageBox.Show(message, title, MessageBoxButton.OK);
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM