Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit 6346174

Browse files
committed
Fixed issue #49
All running VMs are now properly stopped when Manager is closing
1 parent 37cf4cc commit 6346174

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

86BoxManager/frmMain.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ private void cmsVM_Opening(object sender, CancelEventArgs e)
412412
//Closing 86Box Manager before closing all the VMs can lead to weirdness if 86Box Manager is then restarted. So let's warn the user just in case and request confirmation.
413413
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
414414
{
415-
List<ListViewItem> vms = new List<ListViewItem>();
415+
//List<ListViewItem> vms = new List<ListViewItem>();
416+
int vmCount = 0;
416417
if (e.CloseReason == CloseReason.UserClosing && closeTray)
417418
{
418419
e.Cancel = true;
@@ -427,21 +428,22 @@ private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
427428
VM vm = (VM)item.Tag;
428429
if (vm.Status != VM.STATUS_STOPPED && Visible)
429430
{
430-
vms.Add(item);
431+
vmCount++;
431432
}
432433
}
433434
}
434435

435436
//If there are running VMs, display the warning and stop the VMs if user says so
436-
if (vms.Count > 0)
437+
if (vmCount > 0)
437438
{
438439
e.Cancel = true;
439440
DialogResult = MessageBox.Show("It appears some virtual machines are still running. It's recommended you stop them first before closing 86Box Manager. Do you want to stop them now?", "Virtual machines are still running", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
440441
if (DialogResult == DialogResult.Yes)
441442
{
442-
foreach (ListViewItem lvi in vms)
443+
foreach (ListViewItem lvi in lstVMs.Items)
443444
{
444445
lvi.Focused = true;
446+
lvi.Selected = true;
445447
VMStop();
446448
}
447449
Thread.Sleep(1000); //Wait just a bit to make sure everything goes as planned

0 commit comments

Comments
 (0)