如何在windows窗体应用程序中使用windows服务 [英] how to use windows service in windows form application
本文介绍了如何在windows窗体应用程序中使用windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在windows窗体应用程序中使用windows服务?我有数据库表,由黄金、白银等组成.价格.这些可以在 Windows 窗体中显示.
how to use windows service in windows form application? I am having the database table , consists of Gold, silver,etc.. Prices. These can be displayed in Windows Form.
我想在 Windows 窗体中定期更新这些东西(例如:每 10 分钟,需要更新一次).有没有可能的方法?
I want to Update those things periodically in Windows Form(example : for each 10 mins, need to update). Is there possible way available?
推荐答案
可以使用Timer定期更新数据库
You can use Timer to periodically update the database
Timer timer = new Timer();
timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
timer.Interval = (10) * (1); // Timer will tick evert 10 seconds
timer.Enabled = true; // Enable the timer
timer.Start();
void timer_Tick(object sender, EventArgs e)
{
//Put your technique for updating database here
}
你可以像这样调用服务
using System.ServiceProcess;
ServiceController sc = new ServiceController("My service name");
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
}
这篇关于如何在windows窗体应用程序中使用windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文