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.
Step 2
In the Solution Explorer, right-click on the Server and choose "Add Table".
Step 3
The table appears.
Step 4
In the Solution Explorer, right-click on the Screens and choose "Add Screen".
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.
Step 6
The Screen Designer appears.
Step 7
Press F5 to run the application and insert some records (items).
Step 8
In the menu bar, click the Write Code drop down list, and select the "_InitializeWorkSpace method.
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.