Visual Basic (Declaration) | |
---|---|
<LicenseProviderAttribute(System.ComponentModel.LicenseProvider)> Public Class LiveTimer Inherits System.Web.UI.Control Implements ILiveControl |
Visual Basic (Usage) | Copy Code |
---|---|
Dim instance As LiveTimer |
C# | |
---|---|
[LicenseProviderAttribute(System.ComponentModel.LicenseProvider)] public class LiveTimer : System.Web.UI.Control, ILiveControl |
C++/CLI | |
---|---|
[LicenseProviderAttribute(System.ComponentModel.LicenseProvider)] public ref class LiveTimer : public System.Web.UI.Control, ILiveControl |
Visual Basic | Copy Code |
---|---|
'In this example, A LiveTimer periodically updates the color of a LiveLabel 'It also demonstrates using the Tag property to persist information over callbacks Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If (Not Me.IsPostBack) Then 'Set default values for the label LiveLabel1.BorderWidth = New Unit(4) LiveLabel1.BorderColor = Color.Red LiveLabel1.ForeColor = Color.Red 'Use the Tag property to keep track of color index LiveLabel1.Tag = 0 LiveLabel1.Text = "This Message will change color every few seconds" 'Start the Timer. It will fire a Tick event every 2 seconds LiveTimer1.Interval = 2000 LiveTimer1.Start() End If End Sub Private Sub LiveTimer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles LiveTimer1.Tick Dim color As Color = color.Red 'Add 1 to the color index Dim index As Integer = Convert.ToInt16(LiveLabel1.Tag) + 1 LiveLabel1.Tag = index Mod 6 'mod 6 - cycle 0 to 6 Select Case (index) Case 0 color = color.Red Case 1 color = color.Orange Case 2 color = color.Yellow Case 3 color = color.Green Case 4 color = color.Blue Case 5 color = color.Purple End Select 'Update the LiveLabel's Color LiveLabel1.BorderColor = color LiveLabel1.ForeColor = color End Sub |
C# | Copy Code |
---|---|
//In this example, A LiveTimer periodically updates the color of a LiveLabel //It also demonstrates using the Tag property to persist information over callbacks private void Page_Load(object sender, System.EventArgs e) { if (!this.IsPostBack) { //Set default values for the label LiveLabel1.BorderWidth = 4; LiveLabel1.BorderColor = Color.Red; LiveLabel1.ForeColor = Color.Red; //Use the Tag property to keep track of color index LiveLabel1.Tag = 0; LiveLabel1.Text = "This Message will change colors every few seconds!"; //Start the Timer. It will fire a Tick event every 2 seconds LiveTimer1.Interval = 2000; LiveTimer1.Start(); } } private void LiveTimer1_Tick(object sender, System.EventArgs e) { Color color = Color.Red; //Add 1 to the color index int index = Convert.ToInt16(LiveLabel1.Tag) + 1; LiveLabel1.Tag = index%6; //mod 6 - cycle 0 to 6 switch (index) { case 0: color = Color.Red; break; case 1: color = Color.Orange; break; case 2: color = Color.Yellow; break; case 3: color = Color.Green; break; case 4: color = Color.Blue; break; case 5: color = Color.Purple; break; } //Update the LiveLabel's Color LiveLabel1.BorderColor = color; LiveLabel1.ForeColor = color; } |
A LiveTimer is used to raise an event at user-defined intervals. When using the timer, use the LiveTimer.Tick event to perform a polling operation or to display a splash screen for a specified amount of time. Whenever the LiveTimer.Enabled property is set to true and the LiveTimer.Interval property is greater than zero, the LiveTimer.Tick event is raised at intervals based on the LiveTimer.Interval property setting.
If the LiveTimer attempts to raise a callback, and there is a pending LiveTimer callback which has not yet completed, the current callback attempt will be cancelled without any exceptions thrown. This results in a very consistent interval period if every callback completes successfully. One useful advantage of this approach is you can set the Interval property to 1, and the LiveTimer will raise a callback immediately after the previous LiveTimer callback completes, enabling you to update the interface as close to real time as possible. Please note, this behavior does NOT apply to other PowerWEB controls, but is specific to the LiveTimer control. For example, it is possible for the same LiveButton to raise two callbacks at the same time if needed.
Note Due to network lag and other considerations, the LiveTimer interval will not be as precise as a Windows application Timer. Also, the LiveTimer.Interval should be large enough to account for possible delays such as network lag.
This class provides methods to set the interval, and to start and stop the timer.
System.Object
System.Web.UI.Control
Dart.LiveControls.LiveTimer
Target Platforms: Microsoft .NET Framework 2.0