[C#] Restart Problem
#1

Hey guys, ive tried to make an restarter for my Server with C#, all is good but there is one problem but a big^^

 

So then i press a button it start all Server and check if the Process "connector" exist

how can i make that it dont only check if i press a button?

 

Aktually Code :

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Runtime;
using System.Timers;
using System.IO;
using System.Web;
using System.Net;
using System.Windows;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool CheckIfAProcessIsRunning(string processname)
{
return Process.GetProcessesByName(processname).Length > 0;
}

private void button1_Click(object sender, EventArgs e)
{
string Connector;
string GameServer;
string Helper;
string LoginServer;
string Messenger;
bool ProcessRunning;
Connector = @"Server\\Connector\\Connector.exe";
GameServer = @"Server\\GameServer\\GameServer.exe";
Helper = @"Server\\Helper\\Helper.exe";
LoginServer = @"Server\\LoginServer\\LoginServer.exe";
Messenger = @"Server\\Messenger\\Messenger.exe";

if (File.Exists(Connector))
{
Process.Start(Connector);
}
else
{
MessageBox.Show("Konnte Connector nicht finden");
}
if (File.Exists(GameServer))
{
Process.Start(GameServer);
}
else
{
MessageBox.Show("Konnte GameServer nicht finden");
}
if (File.Exists(Helper))
{
Process.Start(Helper);
}
else
{
MessageBox.Show("Konnte Helper nicht finden");
}
if (File.Exists(LoginServer))
{
Process.Start(LoginServer);
}
else
{
MessageBox.Show("Konnte LoginServer nicht finden");
}
if (File.Exists(Messenger))
{
Process.Start(Messenger);
}
else
{
MessageBox.Show("Konnte Messenger nicht finden");
}

ProcessRunning = CheckIfAProcessIsRunning("connector");

while (ProcessRunning == false)
{
Process.Start(Connector);

}
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}[/Code]

 

Btw is here no spoiler?

#2

With this it start the Connector but.. it start it too muuuuchh..^^

 

if (Check== true)
{
bool Test;
Test = CheckIfAProcessIsRunning("connector");
while(Test==false)
{
Process.Start(@"C:\Users\BOSS\Documents\BackUp Complete\Connector\Connector.exe");
}
}[/Code]

#3

use a timer for checkthat is runing in intervall

 

and i wouldnt use always a messagebox you can use for example a label.

also for the phat where the .exe files are located i would make chooseable and not fixed for this look at "FolderBrowserDialog" u will find many exampels.

 

i also would count how many times the process crachs and on waht time Smile

#4

With MsgBox i only used it For test yesterday i crated labels, but there is only one problem.

I dont know how to let him update every Minut, btw it only update it then i click^^

 

Here a example :

 

private void label1_Click(object sender, EventArgs e)
{
bool Test;
Test = CheckIfAProcessIsRunning("connector");
if (Test == true)
{
label1.ForeColor = System.Drawing.Color.Green;
label1.Text = "Connector";
}
else
{
label1.ForeColor = System.Drawing.Color.Red;
label1.Text = "Connector";
}

#5

ofc it only update when u klick how u done it.

 

you need to do that in the checking methode(timer.tick event)

 

for example:

 

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

Timer MyTimer = new Timer();

private void Form1_Load(object sender, EventArgs e)
{
MyTimer.Interval = 6000;
MyTimer.Tick += new EventHandler(MyTimer_tick);

}

private void button1_Click(object sender, EventArgs e)
{
// your code to start the processes

MyTimer.Enabled = true;
MyTimer_tick(sender, e);
}

private void MyTimer_tick(Object myObject,EventArgs myEventArgs)
{
bool Test = CheckIfAProcessIsRunning("connector");
if (Test == true)
{
label1.ForeColor = System.Drawing.Color.Green;
label1.Text = "Connector";
}
else
{
label1.ForeColor = System.Drawing.Color.Red;
label1.Text = "Connector";
}

}

private bool CheckIfAProcessIsRunning(string processname)
{
return Process.GetProcessesByName(processname).Length > 0;
}

#6
Ty hateme, thats what i needed!

#7

One Problem i got :

"Fehler 1 "Timer" ist ein mehrdeutiger Verweis und kann "System.Windows.Forms.Timer" oder "System.Threading.Timer" sein."

 

Its in german but i try to translate :

 

"Timer is a ambiguous reference and can be "System.Windows.Forms.Timer" or "System.Threading.Timer".

 

I think where is something with the namespace?^^

 

so maybe is that solved only need to test :

System.Windows.Forms.Timer MyTimer = new System.Windows.Forms.Timer();

#8
yes i used the "System.Windows.Forms.Timer"

#9

So my Restarter is to 80% Finished (20% Labels and Counter) but i got one Problem:

 

If i start the GameServer with the Restarter it shows the "Cannot load Castle War" error and Crash.

 

But only then i start it with the Restarter..

 

Anyone know how i can solve this?

 

The Code for the Restart/Start :

 

private void button2_Click(object sender, EventArgs e)
{
bool Check;
Check = checkBox1.Visible; // This is for a Funktion, which comes soon..
while (Check == true)
{

bool CheckWer;
CheckWer = CheckIfAProcessIsRunning("werfault");
if (CheckWer == true)
{
Process[] pp = Process.GetProcessesByName("werfault");
foreach (Process p in pp)
{
p.Kill();

}
}

bool CheckConn;
CheckConn = CheckIfAProcessIsRunning("connector");
if (CheckConn == false)
{
Process.Start(@"Server\\Connector\\Connector.exe");
}

bool CheckGS;
CheckGS = CheckIfAProcessIsRunning("Gameserver");
if (CheckGS == false)
{
Process.Start(@"Server\\GameServer\\Gameserver.exe");
}

bool CheckHelp;
CheckHelp = CheckIfAProcessIsRunning("Helper");
if (CheckHelp == false)
{
Process.Start(@"Server\\Helper\\helper.exe");
}

bool CheckLog;
CheckLog = CheckIfAProcessIsRunning("Loginserver");
if (CheckLog == false)
{
Process.Start(@"Server\\LoginServer\\LoginServer.exe");
}

bool CheckMess;
CheckMess = CheckIfAProcessIsRunning("Messenger");
if (CheckMess == false)
{
Process.Start(@"Server\\Messenger\\Messenger.exe");
}

bool CheckCash;
CheckCash = CheckIfAProcessIsRunning("CashServer");
if (CheckCash == false)
{
Process.Start(@"Server\\CashServer\\CashServer.exe");
}

}
}

#10

how it get started normaly? ( sry i need to ask not used ep1 till now )

comes there an startparameta to it?



Forum Jump:


Users browsing this thread: 1 Guest(s)