Search code examples
c#windows-phone-8windows-phoneasync-awaitwindows-phone-toolkit

The 'await' operator can only be used within an async lambda expression Windows Phone 8


I am calling async method on demised of CustomMessageBox left button click. But its giving me complie time error. I googled for it but get some information regarding MessageDialog.Command. How I will achieve same in windows phone CustomMessageBox.

Here is my code

CustomMessageBox customMBox = new CustomMessageBox()
                {
                    Caption = "Alert!",
                    Message = string.Format("Clicking on clear all will clear all the data on the app. Are you sure you want to proceed?"),
                    LeftButtonContent = "Yes",
                    RightButtonContent = "No",
                };

                customMBox.Dismissed += (s2, e2) =>
                {
                    switch (e2.Result)
                    {
                        case CustomMessageBoxResult.LeftButton:
                            await clearDatabaseAsync();
                            break;
                        case CustomMessageBoxResult.RightButton:
                            break;
                        case CustomMessageBoxResult.None:
                            break;
                        default:
                            break;
                    }
                };

                customMBox.Show();

    public async Task clearDatabaseAsync()
    {
       //SQLite clear table record logic
        await App.DeleteDatabase();           

    }

can anyone please suggest me how I will achieve this?

Thanks in Advance.


Solution

  • Try like error says - use async lambda expression:

    customMBox.Dismissed += async (s2, e2) => // rest of the code ...