我正在编写一个小型控制台应用程序(将作为服务运行),基本上是在运行时启动Java应用程序,如果Java应用程序关闭,则关闭自身,并在关闭之前关闭Java应用程序。
我认为前两个功能已经正常工作了,但我不知道如何检测.NET应用程序何时关闭,以便我可以在发生这种情况之前关闭Java应用程序。谷歌搜索只返回有关检测Windows关闭的一堆内容。
有人能告诉我如何处理该部分以及其余部分是否正确吗?
我认为前两个功能已经正常工作了,但我不知道如何检测.NET应用程序何时关闭,以便我可以在发生这种情况之前关闭Java应用程序。谷歌搜索只返回有关检测Windows关闭的一堆内容。
有人能告诉我如何处理该部分以及其余部分是否正确吗?
namespace MinecraftDaemon
{
class Program
{
public static void LaunchMinecraft(String file, String memoryValue)
{
String memParams = "-Xmx" + memoryValue + "M" + " -Xms" + memoryValue + "M ";
String args = memParams + "-jar " + file + " nogui";
ProcessStartInfo processInfo = new ProcessStartInfo("java.exe", args);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
try
{
using (Process minecraftProcess = Process.Start(processInfo))
{
minecraftProcess.WaitForExit();
}
}
catch
{
// Log Error
}
}
static void Main(string[] args)
{
Arguments CommandLine = new Arguments(args);
if (CommandLine["file"] != null && CommandLine["memory"] != null)
{
// Launch the Application
LaunchMinecraft(CommandLine["file"], CommandLine["memory"]);
}
else
{
LaunchMinecraft("minecraft_server.jar", "1024");
}
}
}
}