using System;
using System.Diagnostics;
using System.Threading;
namespace ConsoleApp1
{
class Testing
{
static void Main()
{
string targetProcessName = "Roblox";
TimeSpan maxRuntime = TimeSpan.FromMinutes(2);
Console.WriteLine(string.Format("Monitoring process '{0}'... Will terminate it after {1} minutes.", targetProcessName, maxRuntime.TotalMinutes));
while (true)
{
var processes = Process.GetProcessesByName(targetProcessName);
if (processes.Length > 0)
{
foreach (var process in processes)
{
try
{
DateTime startTime = process.StartTime;
Console.WriteLine(string.Format("Detected '{0}' (PID: {1}) at {2}.", process.ProcessName, process.Id, startTime));
while (!process.HasExited)
{
TimeSpan runtime = DateTime.Now - startTime;
if (runtime > maxRuntime)
{
Console.WriteLine(string.Format("Killing {0} after {1:F2} minutes.", process.ProcessName, runtime.TotalMinutes));
process.Kill();
break;
}
Thread.Sleep(1000);
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Error: {0}", ex.Message));
}
}
}
Thread.Sleep(3000);
}
}
}
}
using System;
using System.Diagnostics;
using System.Threading;
namespace ConsoleApp1
{
class Testing
{
static void Main()
{
string targetProcessName = "Roblox";
TimeSpan maxRuntime = TimeSpan.FromMinutes(2);
Console.WriteLine(string.Format("Monitoring process '{0}'... Will terminate it after {1} minutes.", targetProcessName, maxRuntime.TotalMinutes));
while (true)
{
var processes = Process.GetProcessesByName(targetProcessName);
if (processes.Length > 0)
{
foreach (var process in processes)
{
try
{
DateTime startTime = process.StartTime;
Console.WriteLine(string.Format("Detected '{0}' (PID: {1}) at {2}.", process.ProcessName, process.Id, startTime));
while (!process.HasExited)
{
TimeSpan runtime = DateTime.Now - startTime;
if (runtime > maxRuntime)
{
Console.WriteLine(string.Format("Killing {0} after {1:F2} minutes.", process.ProcessName, runtime.TotalMinutes));
process.Kill();
break;
}
Thread.Sleep(1000);
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Error: {0}", ex.Message));
}
}
}
Thread.Sleep(3000);
}
}
}
}