How to exit loop and app in a Windows Phone 7.8 app?

98 Views Asked by At

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.

2

There are 2 best solutions below

0
On

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.

0
On

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.