private void HandleMode(Mode Mode) { if (!this.Running) { return; } if (Mode == Mode.PACKOPENING) { foreach (var hs in Process.GetProcessesByName("Hearthstone")) { if (hs is Process && !this._hearthstones.Contains(hs)) { hs.EnableRaisingEvents = true; hs.Exited += this.Hs_Exited; this._hearthstones.Add(hs); } } PackScreenEntered.Invoke(this, new EventArgs()); } else { if (this._hearthstones.Count > 0) { this._hearthstones.ForEach(x => { x.Exited -= this.Hs_Exited; x.EnableRaisingEvents = false; }); this._hearthstones.Clear(); PackScreenLeft?.Invoke(this, new EventArgs()); } } }
private void Hs_Exited(object sender, EventArgs e) { if (sender is Process hs) { if (this._hearthstones.Contains(hs)) { hs.Exited -= this.Hs_Exited; hs.EnableRaisingEvents = false; this._hearthstones.Remove(hs); } } if (this._hearthstones.Count == 0) { PackScreenLeft?.Invoke(this, new EventArgs()); } }