Link to home
Start Free TrialLog in
Avatar of vielkacarolina1239
vielkacarolina1239Flag for United States of America

asked on

how to create a job schedule using C# in a console application?

Hi,

I am using C# in visual studio 2005

I need to create a console application that needs to run at 5:00 pm and run a process once per day. I have the following code. Please, see code snippet. however, this is looping all the time and kills the cpu. Please, how can I do the same thing but more efficient. How can I create a windows service that will run every day at 5:00pm and execute my process when is 5:00pm only?

Thanks.
class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                if (DateTime.Now.Hour == 17)
                {
                   myMethod();
                }
            }
        }
 
        static void myMethod()
        {
          //do something
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of elimesika
elimesika
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Melih SARICA
Melih SARICA
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and what Elimesika  is exectly true...
if u try to solve it with code.. what happens when ur code crashes.. it wont run till u restart ur application