user913359
user913359

Reputation: 660

WPF MessageBox Appearing Twice

I am using following code for showing a MessageBox with ok and cancel button. When I click any button same message box appears again. Is there any problem in this code?

        string messageBoxText = "Uploading Data";
        string caption = "Upload Data";
        MessageBoxButton button = MessageBoxButton.OKCancel;                
        // Display message box
        MessageBox.Show(messageBoxText, caption, button, icon);
        MessageBoxResult res = MessageBox.Show(messageBoxText, caption, button, icon);
        if (res == MessageBoxResult.OK)
        {
           count++;              
        }

Upvotes: 0

Views: 1069

Answers (2)

Rohit Sharma
Rohit Sharma

Reputation: 6490

You are calling message box twice via MessageBox.Show. You might want to remove the first

MessageBox.Show(messageBoxText, caption, button, icon);

Upvotes: 2

Prateek Singh
Prateek Singh

Reputation: 863

Because you are calling MessageBox.Show two times...

string messageBoxText = "Uploading Data";
    string caption = "Upload Data";
    MessageBoxButton button = MessageBoxButton.OKCancel;                
    // Display message box
    MessageBox.Show(messageBoxText, caption, button, icon); //**Comment this line**
    MessageBoxResult res = MessageBox.Show(messageBoxText, caption, button, icon);
    if (res == MessageBoxResult.OK)
    {
       count++;              
    }

Upvotes: 5

Related Questions