Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ Usage: StayUp [process] -e -i [interval] -t [timeout]
in seconds. Default is 3600.
-t Time to wait for a process to respond before forcing it
to restart, in seconds. Default is 5.
-d Time to wait between launches in seconds
Default is 0.

Example: StayUp MyApp.exe -e -i 3600 -t 5
Example: StayUp MyApp.exe -e -i 3600 -t 5 -d 10

When event log is enabled, information and errors are recorded logged and
viewable in Windows' Event Viewer. Open the Event Viewer and go to
"Application and Service Logs" > "Stay Up".

-----------------------------------------

Version 1.1.0.5
Version 1.1.0.7

-----------------------------------------

Expand Down
52 changes: 45 additions & 7 deletions StayUp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Program
/// <summary>
/// Version number
/// </summary>
const string kVersion = "1.1.0.6";
const string kVersion = "1.1.0.7";

#endregion
#region Static members
Expand Down Expand Up @@ -137,7 +137,17 @@ class Program
/// Flags whether help message has been displayed
/// </summary>
private static bool sWroteHelpMessage = false;



/// <summary>
/// Delay for relaunch
/// </summary>
private static Timer sRelaunchDelayTimer;

/// <summary>
/// Time between launches
/// </summary>
private static int sRelaunchDelay;
#endregion
#region External

Expand Down Expand Up @@ -316,7 +326,14 @@ public static void Main( string[] args )
} else {
WriteHelp();
}

} else if ( args[ i ] == "-d" ) {
++i;
double timeout = 0.0;
if ( i < args.Length && double.TryParse( args[ i ], out timeout ) ) {
sRelaunchDelay = (int) (timeout * 1000.0);
} else {
WriteHelp();
}
} else {
WriteHelp();
}
Expand All @@ -331,8 +348,8 @@ public static void Main( string[] args )
Environment.Exit( 1 );
return;
}
Console.ReadLine();
while (Console.ReadKey(true).Key != ConsoleKey.Escape) {}

}

/// <summary>
Expand Down Expand Up @@ -367,8 +384,10 @@ static void WriteHelp()
Console.WriteLine( " in seconds. Default is 3600." );
Console.WriteLine( " -t Time to wait for a process to respond before forcing it" );
Console.WriteLine( " to restart, in seconds. Default is 5." );
Console.WriteLine( " -d Time to wait between launches in seconds");
Console.WriteLine( " Default is 0.");
Console.WriteLine( "" );
Console.WriteLine( "Example: StayUp MyApp.exe -e -i 3600 -t 5" );
Console.WriteLine( "Example: StayUp MyApp.exe -e -i 3600 -t 5 -d 5" );
}
}

Expand Down Expand Up @@ -408,7 +427,17 @@ private static void ExitHandler( object sender, EventArgs e )
">> Exit time: " + DateTime.Now.ToString() + "\n" +
GetInfoString(), EventLogEntryType.Error );
}
Launch();

if (sRelaunchDelay > 0)
{
Log("Waiting " + sRelaunchDelay/1000 + "s until relaunch.\nPress ESC to quit");
TimeSpan delay = TimeSpan.FromMilliseconds((double) sRelaunchDelay);
sRelaunchDelayTimer = new Timer(new TimerCallback(RelaunchTimerHandler), null, delay, TimeSpan.FromMilliseconds(-1));
}
else
{
Launch();
}
}

/// <summary>
Expand All @@ -423,6 +452,15 @@ private static void InfoTimerHandler( object sender )
Log( "Process information:\n" + GetInfoString() );
}

/// <summary>
/// Timer called after relaunch delay has elapsed
/// </summary>
/// <param name="sender"></param>
private static void RelaunchTimerHandler(object sender)
{
sRelaunchDelayTimer.Dispose();
Launch();
}
/// <summary>
/// Main application callback
/// </summary>
Expand Down
Binary file modified bin/StayUp.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/launch.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
StayUp CrashTest.exe -e -i 3600 -t 10
StayUp CrashTest.exe -e -i 3600 -t 10 -d 5