我正在开发一个包含两个主要处理的项目,我尝试使用 timer_tick 来处理使应用程序非常慢的处理。应用程序需要始终运行,我希望 timer_tick 的计时器方面每 X 秒触发一次方法,但使用多线程,因为这使它更快。
任何人都可以帮忙吗?
该应用程序的当前结构如下:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
setting_info();
}
public void setting_info()
{
// takes data from config file for API connections
}
private void swis()
{
// connects to API and fetches data
// need to be continuously running - Ideally Interval(1200)
}
private void st_processing()
{
// processes the data that was fetched in swis() slows down the program without multiple threading
// need to be continuously running - Ideally Interval(800)
}
private void alert_in_timer_Tick(object sender, EventArgs e)
{
while (alert_in == true)
{
swis();
break;
}
}
private void st_processing_timer_Tick(object sender, EventArgs e)
{
while (st_processing == true && alert_data_database_has_data == true)
{
st_processing();
//check_error_count();
alert_data_database_has_data = false;
break;
}
}
}