<tfoot id='fx5PX'></tfoot>

    1. <legend id='fx5PX'><style id='fx5PX'><dir id='fx5PX'><q id='fx5PX'></q></dir></style></legend>
        <bdo id='fx5PX'></bdo><ul id='fx5PX'></ul>

    2. <small id='fx5PX'></small><noframes id='fx5PX'>

      <i id='fx5PX'><tr id='fx5PX'><dt id='fx5PX'><q id='fx5PX'><span id='fx5PX'><b id='fx5PX'><form id='fx5PX'><ins id='fx5PX'></ins><ul id='fx5PX'></ul><sub id='fx5PX'></sub></form><legend id='fx5PX'></legend><bdo id='fx5PX'><pre id='fx5PX'><center id='fx5PX'></center></pre></bdo></b><th id='fx5PX'></th></span></q></dt></tr></i><div id='fx5PX'><tfoot id='fx5PX'></tfoot><dl id='fx5PX'><fieldset id='fx5PX'></fieldset></dl></div>

      'await' 运算符只能在异步 lambda 表达式中使用

      时间:2023-10-05
      <legend id='gOQs0'><style id='gOQs0'><dir id='gOQs0'><q id='gOQs0'></q></dir></style></legend>
    3. <i id='gOQs0'><tr id='gOQs0'><dt id='gOQs0'><q id='gOQs0'><span id='gOQs0'><b id='gOQs0'><form id='gOQs0'><ins id='gOQs0'></ins><ul id='gOQs0'></ul><sub id='gOQs0'></sub></form><legend id='gOQs0'></legend><bdo id='gOQs0'><pre id='gOQs0'><center id='gOQs0'></center></pre></bdo></b><th id='gOQs0'></th></span></q></dt></tr></i><div id='gOQs0'><tfoot id='gOQs0'></tfoot><dl id='gOQs0'><fieldset id='gOQs0'></fieldset></dl></div>

        <small id='gOQs0'></small><noframes id='gOQs0'>

          <tbody id='gOQs0'></tbody>

        • <tfoot id='gOQs0'></tfoot>

            <bdo id='gOQs0'></bdo><ul id='gOQs0'></ul>

                本文介绍了'await' 运算符只能在异步 lambda 表达式中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个 c# Windows Store 应用程序.当单击另一个 MessageDialog 内的命令按钮之一时,我正在尝试启动 MessageDialog.这样做的目的是警告用户他们的内容未保存,如果他们单击取消,它将提示他们使用单独的保存对话框进行保存.

                I've got a c# Windows Store app. I'm trying to launch a MessageDialog when one of the command buttons inside another MessageDialog is clicked. The point of this is to warn the user that their content is unsaved, and if they click cancel, it will prompt them to save using a separate save dialog.

                这是我的showCloseDialog"函数:

                Here's my "showCloseDialog" function:

                private async Task showCloseDialog()
                {
                    if (b_editedSinceSave)
                    {
                        var messageDialog = new MessageDialog("Unsaved work detected. Close anyway?", "Confirmation Message");
                
                        messageDialog.Commands.Add(new UICommand("Yes", (command) =>
                        {
                            // close document
                            editor.Document.SetText(TextSetOptions.None, "");
                        }));
                
                        messageDialog.Commands.Add(new UICommand("No", (command) =>
                        {
                            // save document
                            await showSaveDialog();
                        }));
                
                        messageDialog.DefaultCommandIndex = 1;
                        await messageDialog.ShowAsync();
                    }
                }
                

                在 VS 中我得到一个编译器错误:

                In VS I get a compiler error:

                await"运算符只能在异步 lambda 表达式中使用.考虑用'async'修饰符标记这个lambda表达式`

                The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier`

                方法用 await 标记.如果我从 showSaveDialog 之前删除 await,它会编译(并且可以工作),但我会收到警告说我真的应该使用 await

                The method is marked with await. If I remove await from before showSaveDialog, it compiles (and works) but I get a warning that I really should use await

                如何在这种情况下使用 await?

                How do I use await in this context?

                推荐答案

                你必须将你的 lambda 表达式标记为 async,像这样:

                You must mark your lambda expression as async, like so:

                messageDialog.Commands.Add(new UICommand("No", async (command) =>
                {
                    await showSaveDialog();
                }));
                

                这篇关于'await' 运算符只能在异步 lambda 表达式中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 MVVM 在 wpf 中使用 Dialogs 的好坏习惯? 下一篇:如何制作单个实例表单(不是应用程序)?

                相关文章

              • <legend id='xPmbT'><style id='xPmbT'><dir id='xPmbT'><q id='xPmbT'></q></dir></style></legend>

                1. <tfoot id='xPmbT'></tfoot>

                      <bdo id='xPmbT'></bdo><ul id='xPmbT'></ul>

                    <small id='xPmbT'></small><noframes id='xPmbT'>

                    <i id='xPmbT'><tr id='xPmbT'><dt id='xPmbT'><q id='xPmbT'><span id='xPmbT'><b id='xPmbT'><form id='xPmbT'><ins id='xPmbT'></ins><ul id='xPmbT'></ul><sub id='xPmbT'></sub></form><legend id='xPmbT'></legend><bdo id='xPmbT'><pre id='xPmbT'><center id='xPmbT'></center></pre></bdo></b><th id='xPmbT'></th></span></q></dt></tr></i><div id='xPmbT'><tfoot id='xPmbT'></tfoot><dl id='xPmbT'><fieldset id='xPmbT'></fieldset></dl></div>