none
Reminder in winform c# application RRS feed

  • Question

  • Hello guys,
    I'm working on one win from a c# app and I want to have reminder message every Monday, once during the day. What is the best way to do that? This is my code, but it does not do the job for me.
            private DateTime getFirstDate(DayOfWeek day, TimeSpan time)
            {
                DateTime date = DateTime.Today;
                while (date.DayOfWeek != day)
                    date.AddDays(1);
    
                return new DateTime(date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds);
            }
            private void reminder()
            {
                if (DateTime.Now == getFirstDate(DayOfWeek.Monday, new TimeSpan(12, 8, 0)))
                {
                    MessageBox.Show("Hellooo");
                }
            }





    ES

    Monday, January 29, 2018 11:14 AM

Answers

  • I want it to be only if the c # application is open.

    ES

    There is no good way, but this will do it if the program is always open (forget it, the first thing I would do with such a program is remove it)

                if (LastReminder < DateTime.Now)
                {
                    if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
                    {
                        //doSomething and set DateReminder in settings or registry
                    }
    
                }


    Success Cor

    • Marked as answer by dokirt.2 Monday, January 29, 2018 2:56 PM
    Monday, January 29, 2018 1:44 PM

All replies

  • There is no best way using C#, because for this a program needs to be running and that is mostly not the case. 

    Use task scheduler.

    The word new is a little bit funny on this page 

    https://msdn.microsoft.com/en-us/library/bb742545.aspx


    Success Cor

    Monday, January 29, 2018 12:12 PM
  • I want it to be only if the c # application is open.

    ES

    Monday, January 29, 2018 1:13 PM
  • I want it to be only if the c # application is open.

    ES

    There is no good way, but this will do it if the program is always open (forget it, the first thing I would do with such a program is remove it)

                if (LastReminder < DateTime.Now)
                {
                    if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
                    {
                        //doSomething and set DateReminder in settings or registry
                    }
    
                }


    Success Cor

    • Marked as answer by dokirt.2 Monday, January 29, 2018 2:56 PM
    Monday, January 29, 2018 1:44 PM