Gr8t work , help needed

May 29, 2009 at 6:55 AM

Hi there guys,

Gr8t work, I am hoping you can help me I am coming across a sort of random problem, I used the new Business Application Template for SL3.

So what i wanted to do was route an event after a succesfull login and logout to the main page.

If you are familiar with the template this might help.

In the LoginControl.xaml.cs there is an UpdateLoginState method, in here I do this depending if the guy is authenticated or not

                this.RaiseEventEx(new RoutedEventArgsEx(LoggedInEvent));

Then on MainPage.xaml.cs in the OnLoad I add the Event handler
            LoginControl.AddLoggedInEnterHandler(this, new LoginControl.LoggedInRoutedEventHandler(OnLoggedIn));

public void OnLoggedIn(object sender, RoutedEventArgsEx args)
        {
            profileButton.Visibility = Visibility.Visible;
        }
Now this works 100% the first time I run the application, thereafter I get an object reference not set when it runs this the 2nd time
                this.RaiseEventEx(new RoutedEventArgsEx(LoggedInEvent));
Going into your guys code it seems the RoutedEventHandlerData.Hanlder is null the 2nd time, here is the problem though, If i put break points in the code and break before the 1st event has happened, then remove the breakpoint, everything works 100% from there on, I will never get the error again, I only get the error if I dont break on debugging. Somehow the breaking causes something to work

Any help will be appreciated , 

Regards
Shaun Mulligan


Coordinator
May 30, 2009 at 3:53 AM

sounds like a weak reference issue - i willl take a look next week (I am out of town currently).

 

Sep 8, 2009 at 5:42 PM

It is indeed a WeakReference thing... Since the code is generously available, I changed the WeakReferences to "strong" and all was well.

Thanks for this great piece of code! I'm puzzled why Routed Events are not "in-the-box" in the first place? It can't be fear of plugin bloat as demonstrated by how little (albeit elegant) code was needed. Is it perhaps the weak reference thing and fear of memory leaks? I mean, how can you live without Routed Events in any decent SL app? ... was that just a rant? :)