c#代码每天自动运行在9.00 Pm [英] c# code run at 9.00 Pm every day automatic

查看:203
本文介绍了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

这篇关于c#代码每天自动运行在9.00 Pm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆