Note that there are some explanatory texts on larger screens.

plurals
  1. POKilling Java Process from C# Console App
    primarykey
    data
    text
    <p>I posted about this a little while ago, but I resolved the other issue and ran into one more. I am about to deploy this program to 28 hosting machines so I want to make sure this is working before I do so.</p> <p>I wrote a little c# NET application that is basically a wrapper for a Java application, when my app starts, the Java app starts, when my app closes, it closes, and so on.</p> <p>Everything works properly except that when I close my application, the Java application continues to run. When I create the process, I store the Process var in a variable outside of the methods, and then use that when my application goes to shutdown. For whatever reason though it is not terminating the Java application.</p> <pre><code>class Program { private static Process minecraftProcess; 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)) using (minecraftProcess = Process.Start(processInfo)) { minecraftProcess.WaitForExit(); } } catch { // Log Error } } static void Main(string[] args) { Arguments CommandLine = new Arguments(args); // Hook ProcessExit Event AppDomain.CurrentDomain.ProcessExit += new EventHandler(Current_ProcessExit); if (CommandLine["file"] != null &amp;&amp; CommandLine["memory"] != null) { // Launch the Application (Command Line Parameters) LaunchMinecraft(CommandLine["file"], CommandLine["memory"]); } else { // Launch the Application (Default Parameters) LaunchMinecraft("minecraft_server.jar", "1024"); } } static void Current_ProcessExit(object sender, EventArgs e) { System.Threading.Thread.Sleep(10000); // If we have an active Minecraft Service, Shut it down if (minecraftProcess != null) { minecraftProcess.Kill(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload