0

my code get an exception that it could not convert the types enter image description here

        static System.Timers.Timer timer;
        public static void schedule_Timer(DateTime scheduledTime)
        {
        
        DateTime nowTime = DateTime.Now;
        //DateTime scheduledTime = DateTime.Now.AddSeconds(15); //new DateTime((nowTime.Year, nowTime.Month, nowTime.Day, 8, 42, 0, 0); //Specify your scheduled time HH,MM,SS [8am and 42 minutes]
        if (nowTime > scheduledTime)
        {
            scheduledTime = scheduledTime.AddMonths(1);
        }
        double tickTime = (double)(scheduledTime - DateTime.Now).TotalMilliseconds;
       /*my code fall in the next row*/
       timer = new System.Timers.Timer((tickTime));
        timer.Elapsed += new ElapsedEventHandler(DeleteAllNotUsedTasks);
        timer.Start();
    }
    public static void DeleteAllNotUsedTasks(object sender, ElapsedEventArgs e)
    {
        using (ArgamanExpressEntities db = new ArgamanExpressEntities())
        {
            foreach (Dal.Task task in db.Tasks)
            {
                if (task.status == false)
                    db.Tasks.Remove(task);
            }
            db.SaveChanges();
        }
        timer.Stop();
        schedule_Timer(DateTime.Now.AddMonths(1));

    }`
Dilshod K
  • 2,924
  • 1
  • 13
  • 46
  • What is the error message saying in english? – Progman Nov 08 '20 at 14:31
  • @אסתר אליאב - Please, set region language to English before making a screenshots. – Jackdaw Nov 08 '20 at 15:13
  • Did my answer help you resolve the problem? if so, please mark it as accepted by ticking the V to its left. If not, please let me know and I'll try to further help you – OfirD Nov 22 '20 at 10:27

1 Answers1

3

First, to make your life 100x easier, please refer to the answers given on this question to understand how to display Exceptions in English.
This change will allow you to Google exceptions and quickly find answers to problems your'e facing.

After you'll make this change, you'll get the following English exception:

Invalid value '2591982526.9035' for parameter 'interval'.

The reason for this error can be found in Timer.Interval documentation:

The time, in milliseconds, between Elapsed events. The value must be greater than zero, and less than or equal to MaxValue. The default is 100 milliseconds..

Since 2591982526.9035 is larger than Int32.MaxValue, which is 2147483647, you get an exception.

OfirD
  • 9,442
  • 5
  • 47
  • 90