Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6178625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:29:20+00:00 2026-05-24T00:29:20+00:00

I wrote a small program in C# NET a while back to keep a

  • 0

I wrote a small program in C# NET a while back to keep a Java process running. I am about to deploy it to a bunch of servers and I am working on fixing up some of the code now. As it stands, I don’t think I have this setup right.

What would be the best way to keep the process running that I am creating in my LaunchMinecraft() function? I want to have it so as long as my process is running, it continues to restart this process if it crashes.

static void Main(string[] args)
{
    // Launch the Application
    LaunchMinecraft("minecraft_server.jar", "512");
}

public static void LaunchMinecraft(string file, string memory)
{
    string memParams = "-Xms" + memory + "M" + " -Xmx" + memory + "M ";
    string args = memParams + "-jar " + file + " nogui";
    ProcessStartInfo processInfo = new ProcessStartInfo("java.exe", args);
    processInfo.CreateNoWindow = true;
    processInfo.UseShellExecute = false;
    processInfo.RedirectStandardOutput = true;
    processInfo.RedirectStandardInput = true;
    processInfo.RedirectStandardError = true;

    try
    {
        using (Process minecraftProcess = Process.Start(processInfo))
        {
            // Store Process Globally to access elsewhere
            JavaProcess = minecraftProcess;

            // Creates a Repeating Poll Timer (30 Seconds)
            // Use this to keep the Minecraft's Process Affinity/Priority the same as the Daemon
            PollTimer = new System.Timers.Timer();
            PollTimer.Elapsed += new ElapsedEventHandler(Event_PollProcess);
            PollTimer.Interval = 5000;
            PollTimer.Start();

            Console.WriteLine("Minecraft Process Started.");

            // Setup Callback for Redirected Output/Error Streams
            minecraftProcess.OutputDataReceived += new DataReceivedEventHandler(Handler_ProcessOutput);
            minecraftProcess.ErrorDataReceived += new DataReceivedEventHandler(Handler_ProcessError);

            // Steam Writer
            streamWriter = minecraftProcess.StandardInput;

            minecraftProcess.BeginOutputReadLine();
            minecraftProcess.BeginErrorReadLine();

            while (minecraftProcess.HasExited == false)
            {
                String strInput = Console.ReadLine();
                SendProcessCmd(strInput);
            }

            minecraftProcess.WaitForExit();
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:29:21+00:00Added an answer on May 24, 2026 at 12:29 am

    The Process class itself cant prevent your external program from shutting down, you have to use the Exited event as @Jalal mentiones or poll the HasExited property of the process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a small GUI based vb.net program that speaks to embedded devices
I want to write a small program in .NET 4.0 that will open a
I wrote this small program today and I was blown away by the results.
I wrote a small program to check how many bytes char occupies in my
I wrote a small C++ program in VS2k8. When I launch it from windows
I am new at C# and mono. I just wrote a small GtkSharp program
I'm having an issue with a small program that I wrote. It does what
I want to write a small program that should print something like testing CPU...
I need to write a small program that can detect that it has been
I would like to write a small program in C# which goes through my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.