问题主要出在 Read() 方法中。
public static void Read(object source, ElapsedEventArgs e)
{
serverID = File.ReadAllText(sidname);
Console.WriteLine("Current ID: " + serverID);
if (serverID != oldserverID && serverID != "default" && serverID != "")
{
ProcessStartInfo servqueued = new ProcessStartInfo();
servqueued.Arguments = ramlimit + " " + spname + " " + sidname + " " + resourcetxt + " " + ramoutput + " " + rootpath + Path.DirectorySeparatorChar + " " + makeserverpath + " " + Logpath + " " + servqueuepath;
servqueued.FileName = fileservepath;
servqueued.WindowStyle = ProcessWindowStyle.Normal;
servqueued.CreateNoWindow = false;
Process queue;
queue = Process.Start(servqueued);
Console.WriteLine("Server process queued with server name: " + serverID);
File.AppendAllLines(logpath, new string[] { DateTime.Now.ToString("HH:mm:ss tt") + ": ", "Server process queued with server name " + serverID });
oldserverID = serverID;
}
}
不确定为什么 Process.Start 被忽略。该子句的其余部分很好,例如,如果我将 oldserverID 放在开头。
编辑
参数是全局变量,并在脚本前面定义。
编辑
以下是引用的全局变量。注意路径硬编码。
rootpath = "%USERPROFILE%" + Path.DirectorySeparatorChar +"desktop" + Path.DirectorySeparatorChar + "TerrariaServer" + Path.DirectorySeparatorChar + "filebin";
logpath = rootpath + Path.DirectorySeparatorChar + "fr_log.txt";
servqueuepath = rootpath + Path.DirectorySeparatorChar + "queuecheck.txt";
spname = "serverparams.cmd";
sidname = "serverid.cmd";
resourcetxt = rootpath + Path.DirectorySeparatorChar + "ramcheck.txt";
ramoutput = rootpath + Path.DirectorySeparatorChar + "sysresourceoutput.exe";
makeserverpath = rootpath + Path.DirectorySeparatorChar + "update.bat";
Logpath = rootpath + Path.DirectorySeparatorChar + "fsrv_log.txt";
fileservepath = rootpath + Path.DirectorySeparatorChar + "FileServe.exe";
更新
通过使用适当的调试方法(如下),问题源被..解决,标题编辑。