1

What i use:

a list of 10 webbrowsers

a tabIndex ( index of current webbrowser)

different pages that use NavigationService.GoBack() to get to the Mainpage.

the problem:

everytime i use GoBack() to get to the mainpage and navigate, the Navigated-event will be fired 1 time more. Thats a huge performance issue after some surfing but i don't know why it's happening.

what i do in OnNavigatedTo:

fill the webbrowserlist if count != 10 (global list, only 1 time happening)

set Events for every browsers (maybe the problem, but can't imagine why)

thanks for your help.

roqstr
  • 554
  • 3
  • 8
  • 23

1 Answers1

3

If I understand your problem than it is that the webbrowsers Navigated event fires more and more time as you navigate back and forth between the pages.

Without seeing the code I would say that the problem is that you subscribe to the navigated event every time you navigate back to your main page. You could avoid this by:

1) Subscribing to the events in the main pages constructor, becuase it is getting called one time only

2) If you have to subscribe to the events in the pages OnNavigatedTo event than do this checking before:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
                        if (e.NavigationMode != NavigationMode.Back)
                        {
                           webbrowser.tap += someFunction;
                        }
    }

if you need to register to the events every time you navigate to the page than to the following:

  protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
       webbrowser.tap -= someFunction;
    } 
Igor Meszaros
  • 2,081
  • 2
  • 22
  • 46
  • thanks for your answer. You understood the problem, but i need to set the eventhandlers after every goBack(), because i's possible that i added a new WebBrowser to the list that needs to be adjusted, and the current browser has some additional evenhandler. I already tried to set every event to null ( e.g. browsers[i].tap += null) and afterwards set them new, but thats not the solution – roqstr Feb 07 '12 at 22:33
  • No you dont set the eventhandler to null that way, you have to remove it instead... I've edited my original post. – Igor Meszaros Feb 08 '12 at 09:39
  • UPDATE: i was able to deal with it. I added a new global list named "setBrowsers", that is used whenever i add a new webbrowser to "Browsers". the "setBrowserSettings" method is uses this list and clears it afterwards. the only Problem: how can i delete eventhandlers from webbrowsers? – roqstr Feb 08 '12 at 11:48
  • Just copy and paste how you subscribe to an event and change += to -=. – Igor Meszaros Feb 08 '12 at 12:09