I have some session management code in a silverlight application. As part of that session management, I automatically log the user out if they are idle too long. When the user logs in again, any ChildWindow that was open in the previous session will still be open. All other session data is reset though, so the ChildWindow is effectively orphaned. Any attempt to work with it will throw errors. How can I kill any ChildWindows when I do the logout?
How can I find any child window that may exist, and kill it so the logout can work correctly? My first thought is to start looking along the lines of this.GetVisualDescendants().OfType<ChildWindow>(); from the shell. However, in testing, this was empty even when I had a childwindow open.
The app is a silvelight C# app using Prism & MEF.
Edit – adding more detail / another way to phrase the question:
So the program flow would be something like:
- User Logs in to the silverlight Appliction.
- User navigates around in the app and opens a ChildWindow.
- User abandons their computer to refill coffee and ends up in a 20 minute conversation.
- User’s Silverlight “session” times out. All user-specific information is discarded and the login window (another ChildWindow) is shown.
- User returns to computer and sees a login prompt, logs in.
- User sees the ChildWindow they opened just before heading out for coffee.
- User tries to click on something in the ChildWindow and gets an error, since all the context that the ChildWindow had was thrown away when their “session” ended.
I’d like to add to my session timeout code (or even post-login code), something that finds any open ChildWindow and closes it, in order to prevent this situation that leads to the error.
So, I apparently stumped everyone, or more likely didn’t make my question interesting enough.
I did find a way to solve this though. I created a custom base class for all child windows in the application. In that base class, the ChildWindows register/unregister (in Loaded/Unloaded event handlers) themselves from a static list that can be used to get a reference to any active ChildWindows.