Sagar
Sagar

Reputation: 421

UWP app crashing instead of showing message dialogue box

I have a pivot control in my uwp app. In pivot_selectionchanged event i have written to show message dialogue.

After generating the package of uwp app when I have clicked on pivot item some alert message dialogues should display but it is not displaying instead at that point app is crashing. This is with some machines only. Can any one know the reason?

The code I have written is

private void OpenBillPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    bool Isreturn = false;
    bool IsExchange = false;

    Isreturn = checkUserPermission(Constants.Return);
    IsExchange = checkUserPermission(Constants.Exchange);
    if (Application.Current.Resources[Constants.RETURNS].ToString() == Constants.FALSE_CAMELCASE)
        Isreturn = false;
    else
        Isreturn = true;
    if (Application.Current.Resources[Constants.EXCHANGES].ToString() == Constants.FALSE_CAMELCASE)
        IsExchange = false;
    else
        Isreturn = true;

    if ((txtblStatus.Text == "Cancelled" || txtblStatus.Text=="Draft") && (OpenBillPivot.SelectedIndex == 1 || OpenBillPivot.SelectedIndex == 2 || OpenBillPivot.SelectedIndex == 3))
    {
        TransactionDetails.Visibility = Visibility.Collapsed;
        ReturnDetails.Visibility = Visibility.Collapsed;
        ExchangeDetails.Visibility = Visibility.Collapsed;
        //SimpleMessageDialog(ResourceLoader.GetForCurrentView().GetString("PLEASE_CLEAR_THE_BILL"), ResourceLoader.GetForCurrentView().GetString("ALERT"));
    }

    else if (OpenBillPivot.SelectedIndex == 2)
    {
        if ((txtblStatus.Text == "Pending" && txtblBillDue.Text != Constants.ZERO))
        {
            ReturnDetails.Visibility = Visibility.Collapsed;
            ExchangeDetails.Visibility = Visibility.Collapsed;
            SimpleMessageDialog(ResourceLoader.GetForCurrentView().GetString("PLEASE_CLEAR_THE_BILL"), ResourceLoader.GetForCurrentView().GetString("ALERT"));
        }

        else
        {
            if (!Isreturn)
            {
                ReturnDetails.Visibility = Visibility.Collapsed;
                SimpleMessageDialog("Access Denied", ResourceLoader.GetForCurrentView().GetString("ALERT"));
            }
            else
                ReturnDetails.Visibility = Visibility.Visible;
        }

    }

and message dialogue code:

private async void SimpleMessageDialog(string Message, string Title)
{
    MessageDialog dialog = new MessageDialog(Message, Title);
    dialog.CancelCommandIndex = 1;
    await dialog.ShowAsync();
}

Upvotes: 0

Views: 294

Answers (1)

RTDev
RTDev

Reputation: 866

it may be because you are actually not waiting for the message to show, change the return type from void to Task:

private async Task SimpleMessageDialog(string Message, string Title)
{
    MessageDialog dialog = new MessageDialog(Message, Title);
    dialog.CancelCommandIndex = 1;
    await dialog.ShowAsync();
}

and await it:

await SimpleMessageDialog(ResourceLoader.GetForCurrentView().GetString("PLEASE_CLEAR_THE_BILL"), ResourceLoader.GetForCurrentView().GetString("ALERT"));

you need to change the method to async as well:

private async void OpenBillPivot_SelectionChanged...

Upvotes: 1

Related Questions