Reputation: 1
Im polling a view using a timer but after a few rounds of the poll the output goes out of sync. Doesnt matter what the polling time it seems also. Any ideas what is wrong with my code
I'm wondering is it an issue with my timer and or is it the reader
Any ideas would help greatly !
... private void startPoll() {
timer = new Timer(int.Parse(Properties.Settings.Default.DbPoll) * 1000);
timer.Elapsed += OnEventExecution;
//kill timer
timer.Stop();
timer.Start();
System.Diagnostics.Debug.WriteLine("Timer Started " + P Properties.Settings.Default.DbPoll + " secs");
string connectionString;
// MySqlConnection conn;
connectionString = "server=" + Properties.Settings.Default.DbServer + ";database=digital_passports;uid=" + Properties.Settings.Default.DbUser + ";pwd=" + Properties.Settings.Default.DbPass ;
try
{`your text`
using ( var conn = new MySqlConnection(connectionString))
{
try
{
conn.Open();
System.Diagnostics.Debug.WriteLine("Database Connection Connected");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Database Connection Failed..." + ex);
}
var stm = "SELECT * from vtokenpool limit 10";
using (var cmd = new MySqlCommand(stm, conn))
{
stateText.Text = "Running";
stateText.ForeColor = System.Drawing.Color.Green; ;
try
{
using (MySqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
System.Diagnostics.Debug.WriteLine(rdr[0] + " -- " + rdr[1]);
/*
object[] tempRow = new object[rdr.FieldCount];
for (int i = 0; i < rdr.FieldCount; i++)
{
tempRow[i] = rdr[i];
}
dataList.Add(tempRow);
*/
}
rdr.Close();
System.Diagnostics.Debug.WriteLine("Reader Closed");
conn.Close();
System.Diagnostics.Debug.WriteLine("Connection Closed");
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
}
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
Output is below
56 -- q=92e76406787f9ce47292a0e2e87fdce6954f71f76a4773117b907be1e74dc13e
52 -- q=acde8e3015b8c15e66fe0be128718355a3c6fe438732b719f51adb79ca46d7f2
Timer Ended
53 -- q=0c5bf67caf9e5b73de261364b8c79f87b3b27c37613ab7f6a117e91e3454947a
57 -- q=3b225ce87a3157625f9444e90dddfe74580b9ae1258b3c551c300d52012a05fd
54 -- q=06189a2e74841588d0b8a49bbc13f97f20170e2b4d1077382c5cff4a4c12940a
58 -- q=95606d26cb985966a410b98f0bd7cb91e6aebbe36b6d0c0d555e690ed93eeff7
55 -- q=0d1c26e055e45aa89c2dd24c0d17da6c069ef429da3e03fa2af30be36a115f89
Timer Started 5 secs
56 -- q=92e76406787f9ce47292a0e2e87fdce6954f71f76a4773117b907be1e74dc13e
59 -- q=b62fb7f037094f0a6a1a444a94494ea19c88674253bcefb7ad2843b30cbf8763
57 -- https://packagingpassport.com/?q=3b225ce87a3157625f9444e90dddfe74580b9ae1258b3c551c300d52012a05fd
59 -- q=b62fb7f037094f0a6a1a444a94494ea19c88674253bcefb7ad2843b30cbf8763
58 -- q=95606d26cb985966a410b98f0bd7cb91e6aebbe36b6d0c0d555e690ed93eeff7
60 -- q=7f76a8712d5d5507e9b4b2ce126051b6ee310246cc7499fa0acf2c386cfc90c1
59 -- q=b62fb7f037094f0a6a1a444a94494ea19c88674253bcefb7ad2843b30cbf8763
Reader Closed
60 -- q=7f76a8712d5d5507e9b4b2ce126051b6ee310246cc7499fa0acf2c386cfc90c1
Database Connection Connected
Reader Closed
Connection Closed
Database Connection Connected
Connection Closed
Timer Ended
Timer Ended
Timer Started 5 secs
Database Connection Connected
Timer Started 5 secs
60 -- q=7f76a8712d5d5507e9b4b2ce126051b6ee310246cc7499fa0acf2c386cfc90c1
Reader Closed
Connection Closed
Timer Ended
Timer Started 5 secs`
Upvotes: 0
Views: 25
Reputation: 1
Issue was with the timer, have resolved using thread.sleep
Thread.Sleep(int.Parse(Properties.Settings.Default.DbPoll)*1000);
startPoll();
Upvotes: -1