can anyone convert this 5165 autorestarter code to 5533+ code?

04/24/2012 01:39 marcbacor6666#1
Code:
 #region timers
            Thetimer = new System.Timers.Timer();
            Thetimer.Interval = 100000;
            Thetimer.Elapsed += new ElapsedEventHandler(Thetimer_Elapsed);
            Thetimer.Start();
            #endregion

also if u can add a checker of the port to know if port is online or not it will be good

port 9958 or 5816
04/24/2012 12:45 _DreadNought_#2
Sure I can buddy! Anything for you, heard about you, your really good at coding!

Code:
Environment.Exit(0);
That will invoke a restart, you dont need that timer.

I mean it! Pro codes.
04/24/2012 12:51 marcbacor6666#3
its not for restart :P its for exit
04/24/2012 13:22 I don't have a username#4
Your code is not a restarter.
Code:
const int[] RestartHours = new int[]
{
00,
12
// ...
};
private static bool restarted;
private static void Restart()
{
restarted = false;
System.Threading.Thread restartThread = new System.Threading.Thread(
new System.Threading.ThreadStart(delegate
{
while (!restarted)
{
if (RestartHours.Contains(DateTime.Now.Hour) && !restarted)
{
System.Windows.Forms.Application.Restart();
}
System.Threading.Thread.Sleep(10000);
}
}));
restartThread.Start();
}
Add System.Windows.Forms to your references.

If you don't want to use that then use this method.
Code:
private const int[] RestartHours = new int[]
{
00,
12
// ...
};
private const string processName = "ConquerServer.exe";
private static bool restarted;

private static void Restart()
{
restarted = false;
System.Threading.Thread restartThread = new System.Threading.Thread(
new System.Threading.ThreadStart(delegate
{
while (!restarted)
{
if (RestartHours.Contains(DateTime.Now.Hour) && !restarted)
{
System.Diagnostics.Process.Start(processName);
Environment.Exit(0);
}
System.Threading.Thread.Sleep(10000);
}
}));
restartThread.Start();
}
Manual restart method:
Code:
private const string processName = "ConquerServer.exe";

private static void Restart()
{
System.Diagnostics.Process.Start(processName);
Environment.Exit(0);
}
Any problems with it let me know as I just did this out of my head.

Call Restart() a single time from the Main method.

Port check:
Code:
public static bool CheckLocalPort(int Port)
{
try {
System.Net.Sockets.Socket testSocket = new System.Net.Sockets.Socket();
testSocket.Bind(new System.Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), Port));
testSocket.Shutdown(System.Net.Sockets.SocketShutdown.Both);
testSocket.Close();
return true;
}
catch {
return false;
}
}
public static bool CheckExternPort(int Port)
{
try {
System.Net.Sockets.Socket testSocket = new System.Net.Sockets.Socket();
testSocket.Connect(new System.Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), Port));
testSocket.Disconnect(false);
return true;
}
catch {
return false;
}
}
Example usage:
Code:
Console.WriteLine(CheckLocalPort(80));//checking port 80 and writing true if available and false if not.
04/24/2012 13:32 _DreadNought_#5
You do realize I actually had no intention of helping?XD

Ofc that wouldnt restart lol
04/24/2012 13:39 marcbacor6666#6
what .cs will i insert this
04/24/2012 18:49 I don't have a username#7
Any .cs you wanna call them from. I'd say Program.cs
04/25/2012 09:21 marcbacor6666#8
can u put a guide?
04/25/2012 11:03 I don't have a username#9
Ermm.. Learn to code.