0

I have an OberservableCollection that contains data. To check its contents I use a loop that contains MessageBox.Show("...") in order to show each value on the screen.

That works great with the exception that I can not end the app before the end of the loop. That means that the loop is not interrupted on push of home button (Windows logo button). On push the start screen appears, but there are still message boxes that are created by the loop.

Same behavior on emulator and device (Windows Phone 7.8).

Can anyone help me with that please?

Thank you very much in advance.

Ben
  • 81
  • 1
  • 2
  • 1
    I would have the messagebox show both the ok and cancel buttons if the user does not press ok. I would exit the loop with the break statement – Ken Tucker Sep 13 '14 at 12:14

2 Answers2

1

Use OnNavigatedFrom event to find out when the user left the page where the loop started. Set a flag to signal this. Each iteration of the loop check for the value of that flag and if the user already navigated away from your page, just break the loop.

Murven
  • 2,377
  • 17
  • 23
1

You should probably use

MessageBoxResult res = MessageBox.Show("..", "..", MessageBoxButtons.YesNo);
if ( res == MessageBoxResult.OK )
//continue with loop 

This will make sure that the message box is handled by the user and then the loop continues to show the next item, forcing it to be synchronous.

Rushabh
  • 651
  • 5
  • 15