How to execute function below every 10 second by timer ? RRS feed

  • Question

  • Problem
    I need to execute function retrieve image every 10 second by using timer control

    i already put timer control on windows form but how to run and execute this function 

    in timer every 10 second .

    meaning i need every 10 second refresh and executing function below

    I work on windows form c sharp visual studio 2017 with SQL server 2012

    Function below working but remaining how to using in timer and which event will be used ?

    What I have tried:

    public void GetMembersData()
               string sqlGetLast = @"select isnull((select top 1 MemberCode from members order by MemberCode desc),1) ";
               int MemberCode = Utilities.ObjectConverter.ConvertToInteger(DataAccess.ExecuteScalar(sqlGetLast));
               string sqlImage = "select MemberImage FROM Members WHERE MemberCode =" + MemberCode + "";
               if (Utilities.ObjectConverter.ConvertToString(DataAccess.ExecuteScalar(sqlImage)) != "")
                   byte[] MemberImage = (byte[])DataAccess.ExecuteScalar(sqlImage);
                   pictureBox1.Image = ByteArrayToImagebyMemoryStream(MemberImage);

    Hide   Copy Code
    Thursday, March 28, 2019 1:57 AM


  • Greetings.

    There are three types of Timer.

    If this is a Windows.Forms Timer, you can set the interval in the properties, in milliseconds.

    There is only one event, which is the Tick event.

    You put your code into the event handler, like so.

       public partial class Form1 : Form
          public Form1()
             // Start the Timer. You can stop it using timer1.Stop() (of course).
          // Here is the event handler.
          private void timer1_Tick(object sender, EventArgs e)
             // Call GetmemberData in here.

    Thursday, March 28, 2019 2:51 AM