I've got a console application (steamcmd.exe
) which I want to redirect its output to a textbox in my Winforms application.
https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip
I've managed to do that, but the output I get is very inconsistent. For example, I start steamcmd.exe
normally with these arguments
+login anonymous +force_install_dir ./unturned/ +app_update 1110390 validate
This will install the Unturned game server. The output is perfectly fine. It shows the downloading progress consistently.
But when I start steamcmd.exe
using my Winforms application and I redirect its output, it becomes super inconsistent, it could stay stuck at 2% and after a few minutes jump to 58%, the get stuck again and jump to 88% etc.
Here is my code:
steamCMDProc = new Process();
void startSteamCMD()
{
steamCMDProc.EnableRaisingEvents = true;
steamCMDProc.OutputDataReceived += new DataReceivedEventHandler(steamCMD_OutputDataReceived);
steamCMDProc.ErrorDataReceived += new DataReceivedEventHandler(steamCMD_ErrorDataReceived);
steamCMDProc.Exited += new System.EventHandler(steamCMDProcExited);
steamCMDProc.StartInfo.FileName = srvInstDir + @"\steamcmd.exe";
steamCMDProc.StartInfo.Arguments = "login anonymous +force_install_dir ./unturned/ +app_update 1110390 validate";
steamCMDProc.StartInfo.UseShellExecute = false;
steamCMDProc.StartInfo.RedirectStandardError = true;
steamCMDProc.StartInfo.RedirectStandardOutput = true;
steamCMDProc.StartInfo.RedirectStandardInput = true;
steamCMDProc.StartInfo.ErrorDialog = false;
steamCMDProc.StartInfo.CreateNoWindow = true;
steamCMDProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
steamCMDProc.Start();
// inputWriter = steamCMDProc.StandardInput; not currently used
StartThread(steamCMDProcExited); //i start a thread which constantly loops and waits till steamCMD has exited
steamCMDProc.BeginErrorReadLine();
steamCMDProc.BeginOutputReadLine();
}
void steamCMD_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
InvokeIfRequired(textBox2, () => //function that checks if invoke is required
{ textBox2.AppendText(e.Data + Environment.NewLine); });
}
void steamCMD_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
InvokeIfRequired(textBox2, () =>
{ textBox2.AppendText(e.Data + Environment.NewLine); });
}