Windows Services Run at Every Day 12.00 a.m Only. RRS feed

  • Question

  • Hi All,

    This is Ramesh,

    My Requirement is "Windows services run only 12.00 a.m every day(i.e midnight)"..But i have to write some Code  but not correct

    Please once go through the following code as

     static void my_task(Object obj)
                Console.WriteLine("task being performed.");

            static TimerCallback timerDelegate;
            static Timer timer;

            static void Main(string[] args)
                DateTime now = DateTime.Now;
                DateTime today = now.Date.AddHours(0);
                DateTime next = now <= today ? today : today.AddDays(1);

                timerDelegate = new TimerCallback(my_task);

                // hence the first,after the next       
                timer = new Timer(timerDelegate, null, next - DateTime.Now, TimeSpan.FromHours(24));

    I know how to set up the Time intervals  i.e Hrs wise,Mint's wise..Etc...When i am searching "Google" it shows that Schedule Tasks is better option all sites,forums..etc instead of Windows Services But My Managers not agree with me...Could you  please give me valuable suggestion.



    • Moved by Just Karl Friday, September 27, 2013 3:39 PM Looking for the proper forum.
    Friday, September 27, 2013 7:03 AM


All replies

  • Best to ask them over here.





    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

    • Proposed as answer by Just Karl Friday, September 27, 2013 3:39 PM
    • Marked as answer by Just Karl Friday, October 4, 2013 1:29 PM
    Friday, September 27, 2013 2:53 PM
  • Hello,

    This forum is for discussions and questions regarding profiles and Microsoft's recognition system on the MSDN and TechNet sites. It is not for products/technologies.

    As it's off topic here, I am moving the question to the "Where is the forum for..." forum.


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer

    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Friday, September 27, 2013 3:39 PM