locked
refresh all opened screens RRS feed

  • Question

  • in one of my screen's *_Saved() method I would like to refresh every screen that is opened.

    closest i could come up with is:

         foreach (Microsoft.LightSwitch.Client.IActiveScreen ascreen in Application.ActiveScreens)
                    ascreen.Screen.Refresh();

    but it triggers an exception of accesses a screen thats not within the active thread.  Is this possible to do?  thanks

     

    Tuesday, July 5, 2011 9:21 PM

Answers

  • You just need to suround the refresh call with a call to the screen's dispatcher:

    VB:

            For Each ascreen As Microsoft.LightSwitch.Client.IActiveScreen In Application.ActiveScreens
                ascreen.Details.Dispatcher.BeginInvoke( _
                    Sub()
                        ascreen.Screen.Refresh()
                    End Sub
                    )
            Next
    

    C#;

    		foreach (Microsoft.LightSwitch.Client.IActiveScreen ascreen in Application.ActiveScreens)
    		{
    			ascreen.Details.Dispatcher.BeginInvoke(() => {
    					ascreen.Screen.Refresh();
    				});
    		}
    


    Yann

    (plus ça change, plus c'est la même chose!)

    • Proposed as answer by Yann Duran Tuesday, July 5, 2011 10:09 PM
    • Marked as answer by Nehemiah Willis Wednesday, July 6, 2011 4:51 PM
    Tuesday, July 5, 2011 10:09 PM

All replies

  • You just need to suround the refresh call with a call to the screen's dispatcher:

    VB:

            For Each ascreen As Microsoft.LightSwitch.Client.IActiveScreen In Application.ActiveScreens
                ascreen.Details.Dispatcher.BeginInvoke( _
                    Sub()
                        ascreen.Screen.Refresh()
                    End Sub
                    )
            Next
    

    C#;

    		foreach (Microsoft.LightSwitch.Client.IActiveScreen ascreen in Application.ActiveScreens)
    		{
    			ascreen.Details.Dispatcher.BeginInvoke(() => {
    					ascreen.Screen.Refresh();
    				});
    		}
    


    Yann

    (plus ça change, plus c'est la même chose!)

    • Proposed as answer by Yann Duran Tuesday, July 5, 2011 10:09 PM
    • Marked as answer by Nehemiah Willis Wednesday, July 6, 2011 4:51 PM
    Tuesday, July 5, 2011 10:09 PM
  • thanks, I had to do ascreen.Screen.Details.Dispatcher.BeginInvoke.  Also I had to check for null Screen objects to prevent null reference objects. 

    But I'm noticing strange behavior with the refresh function.  All opened tabs will show a refresh symbol but it looks like only the last tab that is refreshed and becomes the active screen will actually show the refreshed data.  I tried this with 2 screens, when set it up where screen 1 refreshed last, screen 2 still did not show the updated changes even through it looked like it reloaded that tab.  I then I changed it to vice versa, and when screen 2 was refreshed last it became the active screen and screen 1 did not show the updated changes.

    Tuesday, July 5, 2011 11:02 PM
  • Sorry about the code mixup. I took it from an extension method that I wrote that was slightly different to your code (my method refreshes only screens of a specific "type"), & then modified it to apply your scenario. In my code, the object I was using where you have "ascreen" was already an IScreenObject.

    I haven't actually had a need to refresh multiple screens at one time, even though that's what my extension method does, it's usually just refreshing a parent screen. I haven't had a situation with multiple screens open when I used it (I wrote the method to handle multiple screens, just in case I ever did have multiples open).

    So maybe you've discovered a bug.


    Yann

    (plus ça change, plus c'est la même chose!)

    Wednesday, July 6, 2011 1:00 AM