Wait to finish before doing the next task
<p>i have a server application with a richtextbox as the console text basically. The problem is, i have start, restart and stop buttons - But my restart button doesn't work.</p>

<p>Heres my code for the restart button:</p>

<pre><code>consoletxt("RESTART", "Restarting Server...");
statuslabel1.Text = "Restarting";
statuslabel1.ForeColor = Color.Orange;
statuslabel2.Text = "Restarting";
statuslabel2.ForeColor = Color.Orange;

command("stop");

//The performclick just starts the server
startbtn.PerformClick();

statuslabel1.Text = "Online";
statuslabel1.ForeColor = Color.DarkGreen;
statuslabel2.Text = "Online";
statuslabel2.ForeColor = Color.DarkGreen;
consoletxt("RESTART", "Restart completed, server online!");
</code></pre>

<p>However, the output is this:</p>

<pre><code>2012-04-01 11:32:12 [RESTART] Restarting Server...
2012-04-01 11:32:12 [RESTART] Restart completed, server online!
2012-04-01 11:32:12 [INFO] CONSOLE: Stopping the server..
2012-04-01 11:32:12 [INFO] Stopping server
</code></pre>

<p>So, it says that the restart has finished in the text - but it hasn't - all it has done is stop the server.</p>

<p>CODE FOR PERFORMCLICK:</p>

<pre><code> try { var x = ServerProc.StartTime; return; }
            catch { }
            try
            {
                ServerProc.Start();
                ServerProc.BeginErrorReadLine();
                statuslabel1.Text = "Online";
                statuslabel1.ForeColor = Color.DarkGreen;
                statuslabel2.Text = "Online";
                statuslabel2.ForeColor = Color.DarkGreen;

            }
</code></pre>

<p>Please can sombody explain to me how to do this properly?</p>

<p>Thanks!</p>
