AutoRefresh a Screen in LightSwitch 2012

Here we will see how to autorefresh a screen in a LightSwitch Application (Visual C#) in Visual Studio 2012.

The following is the procedure for autorefreshing a screen.

Step 1

Open the Solution Explorer.

sol explo.jpg

Step 2

In the Solution Explorer, right-click on the Server and choose "Add Table".

Add Table.jpg

Step 3

The table appears.

Item table.jpg

Step 4

In the Solution Explorer, right-click on the Screens and choose "Add Screen".

Add src.jpg

Step 5

The Add New Screen dialog box appears. Select the "Editable Grid Screen" from the Screen Template, under screen information, choose "Item" under screen data and provide a name to the Screen and click the "OK" button.

editable src.jpg

Step 6

The Screen Designer appears.

app desi.jpg

Step 7

Press F5 to run the application and insert some records (items).

output.jpg

Step 8

In the menu bar, click the Write Code drop down list, and select the "_InitializeWorkSpace method.

write code.jpg

The code designer appears.

using System;

using System.Linq;

using System.IO;

using System.IO.IsolatedStorage;

using System.Collections.Generic;

using Microsoft.LightSwitch;

using Microsoft.LightSwitch.Framework.Client;

using Microsoft.LightSwitch.Presentation;

using Microsoft.LightSwitch.Presentation.Extensions;

using System.Windows.Threading;

using Microsoft.LightSwitch.Threading;

namespace LightSwitchApplication

{

    public partial class EditableItemsGrid

    {

       

        partial void EditableItemsGrid_InitializeDataWorkspace(List<IDataService> saveChangesTo)

        {

            Dispatchers.Main.BeginInvoke(() =>

                {

                    T.Tick += new EventHandler(Each_Tick);

                });

 

        }

 

        private static readonly DispatcherTimer T= new DispatcherTimer()

        {

            Interval = TimeSpan.FromMinutes(10)

        };

 

        private void Each_Tick(object sender, EventArgs e)

        {

           

            Dispatchers.Main.BeginInvoke(() =>

                {

                    Items.Refresh();

                });

        }

    }

}

Step 9

Press F5 to run the application. When you run the application the screen will be refreshed every 10 seconds. 

output.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all