yefj
Advanced Member level 5
Hello, i have sucsseeded building in visual studio .NET framework a code that sends commands when i press a button as shown bellow.
I want to modify my code so it will send this command every second and to stop sending the command when i press another button.
Google says i should use timer(and event handler), but timer needs static method.
i didn't use "public static void main()" in my code so far and it worked fine.
why in timer we have to use static methods?
Thanks.
I want to modify my code so it will send this command every second and to stop sending the command when i press another button.
Google says i should use timer(and event handler), but timer needs static method.
i didn't use "public static void main()" in my code so far and it worked fine.
why in timer we have to use static methods?
Thanks.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Timers;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
bool meter_state = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.Write("meas:freq:st 500 mhz\n");
serialPort1.Write("*idn?\n");
string data = serialPort1.ReadTo("\n");
textBox1.AppendText(data);
serialPort1.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Last edited: