usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Diagnostics;usingsystem.timers;namespacecmdpython{classProgram {Static voidMain (string[] args) {Timer Timer=NewTimer (60000); //timer. Interval = 60000;//execution interval time: 60 seconds, in milliseconds, one minute to judgetimer. Enabled=true; Timer. Elapsed+=NewElapsedeventhandler (timer1_elapsed); Timer. AutoReset=true; Timer. Start (); Console.WriteLine ("the Python drawing program starts with a daily average value of 9:20; hour: 6:30. Execution"); Console.ReadLine (); } Private Static voidTimer1_elapsed (Objectsender, System.Timers.ElapsedEventArgs e) { //get hour minute second start executing a program if it equals a value. intInthour =E.signaltime.hour; intIntminute =E.signaltime.minute; if(Inthour = =9&& Intminute = = -) {Console.WriteLine ("start to perform daily average value drawing,"+e.signaltime.date); Dopython ("python","e:/python/drawyesteday_day.py"); } if(Inthour = =6&& Intminute = = -) {Console.WriteLine ("start the execution of the time-out drawing,"+e.signaltime.date); Dopython ("python","e:/python/drawyesteday_hour.py"); } } Private Static voidDopython (stringStartFileName,stringStartfilearg) {Process cmdprocess=NewProcess (); CmdProcess.StartInfo.FileName= StartFileName;//CommandCmdProcess.StartInfo.Arguments = Startfilearg;//ParametersCmdProcess.StartInfo.CreateNoWindow=true;//do not create a new windowCmdProcess.StartInfo.UseShellExecute =false; CmdProcess.StartInfo.RedirectStandardInput=true;//REDIRECT inputCmdProcess.StartInfo.RedirectStandardOutput =true;//REDIRECT standard outputCmdProcess.StartInfo.RedirectStandardError =true;//REDIRECT error output//CmdProcess.StartInfo.WindowStyle = Processwindowstyle.hidden; Cmdprocess.start (); Cmdprocess.beginoutputreadline (); Cmdprocess.beginerrorreadline (); //If you open a comment, the command executes synchronously, and this example executes asynchronously with the exited event. Cmdprocess.waitforexit (); Cmdprocess.close (); } }}
C # timed Python script execution