Show champs ingame

This commit is contained in:
2026-04-29 18:15:21 +02:00
parent 06d5113711
commit 9f6105b970
5 changed files with 260 additions and 40 deletions
+69
View File
@@ -0,0 +1,69 @@
using System.Diagnostics;
namespace LeagueAPI.Utils;
public class ProcessWatcher : IDisposable
{
private bool _isDisposed;
private Timer _timer;
public bool IsGameRunning { get; private set; } = false;
public event EventHandler? LeagueOfLegendsExeFound;
public TimeSpan Interval
{
get => field;
set
{
if (field != value)
{
field = value;
_timer?.Change(TimeSpan.Zero, value);
}
}
} = TimeSpan.FromSeconds(10);
public ProcessWatcher()
{
_timer = new(OnTimerTick, null, TimeSpan.Zero, Interval);
}
private void OnTimerTick(object? state)
{
if (Process.GetProcessesByName("League of Legends").Length != 0)
{
if (!IsGameRunning)
{
LeagueOfLegendsExeFound?.Invoke(this, EventArgs.Empty);
}
IsGameRunning = true;
}
else
{
IsGameRunning = false;
}
}
#region IDisposable
protected virtual void Dispose(bool disposing)
{
if (!_isDisposed)
{
if (disposing)
{
_timer?.Dispose();
}
_isDisposed = true;
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
#endregion
}