首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows Phone 8.1模式对话框。多么?

Windows Phone 8.1模式对话框。多么?
EN

Stack Overflow用户
提问于 2016-03-08 09:58:28
回答 1查看 99关注 0票数 0

按照Stack Overflow中的示例,我组合了一个MessageDialog来显示我的用户错误消息。在模拟器中,它工作得很好。

在手机上,它会被击穿,屏幕上的MessageDialog只会闪烁片刻,甚至会击穿我放入的Task.Delay作为变通办法。

谁能给我解释一下发生了什么事,或者给我指个正确的方向?

附注:我还在这里尝试了每篇文章的ContentDialog。它甚至不显示消息文本。

下面是一个代码片段:

代码语言:javascript
复制
public static async void ShowAndGo (String MessCode, String MessText, Boolean Xit)
{
    String Mess = "";                               // Start out with an empty Message to tell Joe User.
    String Title = "";                              // And an empty title too.

    if (MessCode != "")                             // If we're sent a Message "Code,"
        Mess = App.ResLdr.GetString (MessCode) + Cx.ld + Cx.ld; // turn it into text, culturally-aware.
    Mess += MessText;                               // Stick MessText onto the end of it.

    if (Xit)
        Title = App.ResLdr.GetString ("OhSnap");    // If we're goin' down, curse a little.
    else
        Title = App.ResLdr.GetString ("NoProb");    // If it's just informational, no problem-o.

    MessageDialog messageDialog = new MessageDialog (Mess, Title);
    await messageDialog.ShowAsync ();               // IT FREAKING ISN'T STOPPING HERE!!!
    Task.Delay (10000).Wait ();                     // Wait 10 seconds with error message on the screen.
                                                    // AND IT FREAKING DOESN'T STOP HERE EITHER!!!
}
EN

回答 1

Stack Overflow用户

发布于 2016-03-08 14:05:05

问题的原因很简单--你声明了async void方法--避免这一点,这应该只在特殊情况下使用,例如事件。在您已有的代码中,您的程序不会在您调用该方法的地方停止:

代码语言:javascript
复制
ShowAndGo("Message code", "Message Text", false);
Debug.WriteLine("Something happening");

它可能会显示一条消息,但它能存活多长时间取决于您的后续代码。解决此问题的方法是将方法从void更改为Task and await

代码语言:javascript
复制
public static async Task ShowAndGo (String MessCode, String MessText, Boolean Xit)
{  /* method */ }

//invoke:
await ShowAndGo("Message code", "Message Text", false);
Debug.WriteLine("Something happening"); // now it should wait till user clicks OK

当然,这需要所有的异步,但这可能就是你的程序应该看起来的样子。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35857566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档