c#代码每天自动运行在9.00 Pm

问题描述:

如何使用System.Runtime.InteropServices控制此代码在每9.00 PM

How can I con trol this code to run every 9.00 PM

using System.Runtime.InteropServices;

[DllImport("kernel32.dll")]
static extern int GetShortPathName(string longPath, StringBuilder buffer, int bufferSize);



public void Batch()
{
StringBuilder buffer = new StringBuilder(256);
GetShortPathName(Path.GetDirectoryName(MySqlEXEPath), buffer, buffer.Capacity);
string shortfilename = buffer.ToString();

string BatchFile = @"c:\temp\Batch.bat";
StreamWriter sw = new StreamWriter(BatchFile);
sw.WriteLine("cd " + shortfilename);
sw.WriteLine(@"mysql -uroot -pXXX DB_NAME < C:\TEMP\FILE.SQL");
sw.Flush();
sw.Close();

//IMPORTANT, DO NOT FORGOT THIS
Environment.CurrentDirectory = @"c:\windows\";

Process.Start(BatchFile);

}


使用Windows计划程序请参见 http://msdn.microsoft .com / en-us / library / aa384006%28v = VS.85%29.aspx ,创建新任务并将其设置为

You can use Windows Scheduler see http://msdn.microsoft.com/en-us/library/aa384006%28v=VS.85%29.aspx, create new task and set it as


所有程序 - > accessories-> system
tools->预定任务从
今天开始每天上午9:00执行此任务每日

all programs->accessories->system tools->scheduled task Start today at 9:00 am Perform this task Every Day