C# Programming
02-15-2010, 06:11 PM
Forgive my newbie question. I am trying to learn C#. I have utterly confused myself in trying to restart a server console. I do not have the server start on this yet but it locks up every time I restart and I am not real sure way. It shutsdown ok but then never makes the check if the process has exited. Can anyone give me a nudge in the right direction? Thanks
public void restartserver(string serverrs, string serverloc)
{
Process p = Process.GetCurrentProcess();
Process[] servername = Process.GetProcessesByName(serverrs);
IntPtr serverHandle = FindWindow(null, serverloc);
if (serverHandle == IntPtr.Zero)
{
if (serverrs == "arcemu-world")
{
btnWorldStatus.Text = "World Server is not running";
}
else {
btnLogonStatus.Text = "Logon Server is not running";
}
}
else {
SetForegroundWindow(serverHandle);
SendKeys.SendWait("Shutdown{ENTER}");
FreeConsole();
bool mytrue = true;
while (mytrue)
{
if (p.HasExited)
{
mytrue = false;
if (serverrs == "arcemu-world")
{
btnWorldStatus.Text = "Closing....";
}
else {
btnLogonStatus.Text = "Closing....";
}
}
}
}
}
public void restartserver(string serverrs, string serverloc)
{
Process p = Process.GetCurrentProcess();
Process[] servername = Process.GetProcessesByName(serverrs);
IntPtr serverHandle = FindWindow(null, serverloc);
if (serverHandle == IntPtr.Zero)
{
if (serverrs == "arcemu-world")
{
btnWorldStatus.Text = "World Server is not running";
}
else {
btnLogonStatus.Text = "Logon Server is not running";
}
}
else {
SetForegroundWindow(serverHandle);
SendKeys.SendWait("Shutdown{ENTER}");
FreeConsole();
bool mytrue = true;
while (mytrue)
{
if (p.HasExited)
{
mytrue = false;
if (serverrs == "arcemu-world")
{
btnWorldStatus.Text = "Closing....";
}
else {
btnLogonStatus.Text = "Closing....";
}
}
}
}
}