我开发了一个控制台应用程序,必须在后台运行。该应用程序必须不断检查数据库是否有新记录。如果返回了新记录,则对其进行处理。目前,我的应用程序使用 while(true) 语句来保持应用程序的运行。使用 while 循环是否是最佳解决方案?
我的代码片段:
我的代码片段:
static void Main(string[] args)
{
while(true)
{
// Query db for new records
if(record_count > 0)
{
// Process the records
}
Thread.Sleep(500);
}
}