简体   繁体   中英

How to make a reminder in C# using System.Timers.Timer and System.Threading

I am trying to create a simple appointment remainder app where I would get remainder of an appointment 15 minutes earlier to the appointment time. I am calling the timer1_Tick(object sender, EventArgs e) function on form load.

private void timer1_Tick(object sender, EventArgs e)
    {
        try
        {
        DateTime now = DateTime.Now;
        //now = now.AddMinutes(10);
        now = now + TimeSpan.FromMinutes(15);
        string longtime = now.ToString("hh:mm:ss tt");//    "03:46:00 PM";
        string shortdate = now.ToString("dd/MM/yyyy"); //"21/02/2015";
        MySqlCommand cmdchk = new MySqlCommand("select * from tbl_appointment where adate=@adte and atime=@time", con);
        cmdchk.Parameters.AddWithValue("@adte", shortdate);
        cmdchk.Parameters.AddWithValue("@time", longtime);
        dr = cmdchk.ExecuteReader();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                appointmentid = dr.GetInt32(0);
                smsmobile = dr.GetString(2);
            }
            dr.Close();
            Frm_app_pop pop = new Frm_app_pop();
            pop.appointmentid = appointmentid.ToString();
            pop.Show();
            words[0] = appointmentid;
        }
        dr.Close();
        dr.Dispose();
        if (flags.remiderflag == true)
        {
            remindtimer.Start();
        }
        dr.Close();


        }
        catch (Exception ex)
        {
            string exce = ex.Message;
        }
    }

I have set the time interval to 1 second. For every second, the timer1_Tick function is run which connects to database and gets the time in longtime which is the the time on which I want to set the reminder.

When I run this code, it runs fine but I am not getting any reminder (which should be displayed using pop.show() ), neither there is any error in this code.

Please share a solution to this problem.

Check your network connectivity and firewall checking. From command line, you have to run the following commands and if it is succeeded, you can send mail.

  1. ping google.com
  2. tracert google.com

After that put ssl.enable property to false.

尝试将mail.imap.connectiontimeout javamail属性的值mail.imap.connectiontimeout例如10000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM