public static void Main(string[] args) { int i = 0; while (i < 4) { int CheckFlag = 0; //int SkipFlag = 0; //string query1 = "select skip_flag from dbo.flags where row_id = 1"; string query2 = "select chk_flg from dbo.flags where row_id = 1"; Dbcheck d = new Dbcheck(); //SkipFlag = d.SelectDbMethod(query1); CheckFlag = d.SelectDbMethod(query2); if (CheckFlag == 1) { DbUpdate A = new DbUpdate(); switch (i) { case 0: A.UpdateDbMethod('P', 0, 0); i = 0; Environment.Exit(1); break; case 1: A.UpdateDbMethod('R', 0, 0); i = 0; Environment.Exit(1); break; case 2: A.UpdateDbMethod('L', 0, 0); i = 0; Environment.Exit(1); break; case 3: A.UpdateDbMethod('S', 0, 0); i = 0; Program sms = new Program(); sms.SmsMethod(); Environment.Exit(1); break; } } else { Console.WriteLine("Its Time to take medication"); if (i == 3) { //DbUpdate A = new DbUpdate(); //A.UpdateDbMethod('S', 1, 0); //Program sms = new Program(); //sms.SmsMethod(); //break; } } i++; System.Threading.Thread.Sleep(60000); } }