I'd suggest the follwing steps:
1) create a new c# winforms applikation.
2) if you need to manualy start or stop the query add a button to do so.
3) add a timer and a backgroundworker to your form.
4) set the timmerintervall to 30 seconds and start the backgroundworker each timer the timer ticks.
5) put the query inside the backgroundworker and put each line into a List<string>
6) add the backgroundworker.RunWorkerCompleted - event.
7) add a new form on which you put a listbox for the result.
8) add a button to your second form to close it or a timer for autoclose
9) now you have some different ways to get the query result into your second form. maybe it's the easiest if you make the listbox in second form public.
10) your code in your primary form might be sth like this:
void Button1Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync()
}
void BackgroundWorker1DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
List<string> liste=new List<string>();
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = "server=(local);database=modelDb;user id=sa;pwd=Esi2008*";
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())
{
liste.Add("Leak Location\t\t Latitude\t\t Longitude\t\t Leak Occured Time");
while (reader.Read())
{
liste.Add(String.Format("{0}\t\t |\t{1}\t|\t{2}\t|\t{3}", reader[0], reader[1], reader[2], reader[3]));
}
}
}
}
e.Result=liste;
}
void BackgroundWorker1RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
Form2 form2=new Form2();
form2.Show();
foreach(string s in (List<string>e.Result) form2.listBox1.Items.Add(s);
}
where Form2 is your second Form and liste the List<string> with all the lines from query result. This would open a new popup form each time the query runs.