public class Worker
{
private Boolean Running = false;
public Boolean Work = true;
private Process[] Processes;
public event EventHandler<WorkerEventArgs> WorkerEvent;
public virtual void OnWorkerEvent(String _Event)
{
if (WorkerEvent != null) WorkerEvent(this, new WorkerEventArgs(_Event));
}
public void Start()
{
while (Work)
{
Processes = Process.GetProcessesByName("iw4mp.dat");
if (Processes.Count() >= 1)
{
if (!Running)
{
OnWorkerEvent("Run");
}
Running = true;
Thread.Sleep(2500);
}
else
{
if (Running)
{
OnWorkerEvent("Exit");
}
Running = false;
Thread.Sleep(2500);
}
foreach (var A in Processes)
{
A.Dispose();
}
}
}
}
This class is leaking memory each 2.5 seconds (Yes, i monitored the memory usage with the Task Manager) when i call a ThreadStart with the Start() function. Any ideas on why is this happening...?
Basically, the Start() method should just poll if iw4mp.dat is running, even though it works... i have no idea why it keeps allocating memory each loop...