I don't think there is any need for threading if waiting and SQL-Output is all what your programm is doing.
So my suggestion is
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace LeakLocationFinder
{
class Program
{
static void Main(string[] args)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = "server=(local);database=modelDb;user id=sa;pwd=123456";
conn.Open();
SqlCommand command = new SqlCommand("DECLARE @var varchar(1000) = (SELECT TOP 1 Text FROM Alarms WHERE AlarmDefinitionId=139 ORDER BY EventTime DESC) DECLARE @start_position int, @end_position int SELECT @start_position = PATINDEX('% at%', @var) SELECT @end_position = PATINDEX('%kilometers%', @var) DECLARE @VALUE VARCHAR(10) = (Select SUBSTRING(@var, @start_position+5,5)) Select Top 1 @VALUE,RouteTable.Latitude,Routetable.Longitude,Alarms.EventTime FROM Alarms INNER JOIN Routetable ON Routetable.Location BETWEEN FLOOR(@VALUE)-1 AND CEILING(@VALUE)+1 WHERE AlarmDefinitionId=139 ORDER BY EventTime DESC", conn);
do{
using (SqlDataReader reader = command.ExecuteReader())
{
Console.clear();
Console.WriteLine("Column1\t\tColumn2\t\tColumn3\t\t");
while (reader.Read())
{
Console.WriteLine(String.Format("\t{0} \t\t | {1} \t\t | {2} \t",
reader[0], reader[1], reader[2]));
}
}
Thread.Sleep(120000);
} while (true);
}
}
}
}
(I hope I closed all curly brakets)