`using System;
using System.Diagnostics;
using System.Linq;
namespace BubbleKiller
{
class Program
{
static void Main(string[] args)
{
while (true)
{
bool isNOTrunning = false;
bool ISrunning = false;
bool bubblesKilled = false;
bool secondTime = false;
// Get all running processes with name "bubbles.scr"
Process[] bubbles = Process.GetProcessesByName("bubbles.scr");
if (bubbles.Length == 0)
{
isNOTrunning = true;
ISrunning = false;
}
else if (bubbles.Length == 1 && !secondTime)
{
ISrunning = true;
}
if (ISrunning && !bubblesKilled)
{
foreach (var bubble in bubbles)
{
bubble.Kill();
bubblesKilled = true;
}
}
if (bubblesKilled)
{
isNOTrunning = true;
ISrunning = false;
}
if (bubblesKilled && isNOTrunning)
{
secondTime = true;
ISrunning = true;
bubblesKilled = true;
Process.Start("bubbles.scr");
}
// Introduce a small delay to avoid excessive CPU usage
System.Threading.Thread.Sleep(10);
}
}
}
}`
Well, I got this C# code, but there’s just a small issue, it repeatedly terminates and runs the “bubbles.scr” process every 0.01 second (I know the ‘System.Threading.Thread.Sleep(1000);’ is responsible for the 0.01 second thing), BUT here’s the thing, we need it to check for and terminate every running “bubbles.scr” task, BUT when it kills one, it launches ANOTHER case of “bubbles.scr” in place of the one being killed, and then it just stops trying to run, or terminate any other instances of bubbles.scr after that.
So basically, keep frantically looking for “bubbles.scr” (with a delay of 10ms), finds one, kills it, launches another instance of bubbles.scr (with a delay of 10ms), stops doing any of the previous stuff until the bubbles.scr we launched is stopped via the user, then it goes back to hunting.
Side Note: We need the ‘while (true)’ part because we want it to be consistently looking for bubbles.scr.
Tried: A script that looks for bubbles.scr, kills it, and launched another instance (ONCE)
Happened: It kept killing and launching instances of bubbles.scr.
FancyDoggy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.