Action by timer. Getting Started

In this lesson, you will learn how to set the executing of Simple Action by timer in Windows Forms Application. You need to create a new controller and use WinAutoExecuteController during implementation one of methods. Code snippet below demonstrates how to set the execution dialogController.AcceptAction in OnViewChanged() event handler. Action will be executed automatically after 9 seconds after the event occures.

  • c#
  • VB

protected override void OnViewChanged()
{
  base.OnViewChanged();
  if (this.View.CurrentObject is ParametersObject)
  {
    var autoExecuteController = this.Frame.GetController<WinAutoExecuteController>();
    if (autoExecuteController != null)
    {
      var dialogController = this.Frame.GetController<DialogController>();
      if (dialogController != null && dialogController.AcceptAction != null)
      {
        autoExecuteController.InitializeCountDown(9, dialogController.AcceptAction);
      }
    }
  }
}

Protected Overrides Sub OnViewChanged()
  MyBase.OnViewChanged()
  If TypeOf Me.View.CurrentObject Is ParametersObject Then
    Dim autoExecuteController = Me.Frame.GetController(Of WinAutoExecuteController)()
    If autoExecuteController IsNot Nothing Then
      Dim dialogController = Me.Frame.GetController(Of DialogController)()
      If dialogController IsNot Nothing AndAlso dialogController.AcceptAction IsNot Nothing Then
        autoExecuteController.InitializeCountDown(9, dialogController.AcceptAction)
      End If
    End If
  End If
End Sub

As you can see, InitializeCountDown() method takes 2 parameters: the countdown time in seconds and and the Simple Action that must be started by timer. WinAutoExecuteController also exposes methods for controlling the timer.