Fix NRE on cancel when there's nothing to cancel.

This commit is contained in:
Michael Bucari-Tovo 2022-06-20 16:47:25 -06:00
parent 91db665428
commit e787d33e5a

View File

@ -212,7 +212,8 @@ namespace LibationWinForms.ProcessQueue
private async void cancelAllBtn_Click(object sender, EventArgs e) private async void cancelAllBtn_Click(object sender, EventArgs e)
{ {
Queue.ClearQueue(); Queue.ClearQueue();
await Queue.Current?.CancelAsync(); if (Queue.Current is not null)
await Queue.Current.CancelAsync();
virtualFlowControl2.VirtualControlCount = Queue.Count; virtualFlowControl2.VirtualControlCount = Queue.Count;
UpdateAllControls(); UpdateAllControls();
} }
@ -331,7 +332,8 @@ namespace LibationWinForms.ProcessQueue
ProcessBook item = Queue[queueIndex]; ProcessBook item = Queue[queueIndex];
if (buttonName == nameof(panelClicked.cancelBtn)) if (buttonName == nameof(panelClicked.cancelBtn))
{ {
await item.CancelAsync(); if (item is not null)
await item.CancelAsync();
Queue.RemoveQueued(item); Queue.RemoveQueued(item);
virtualFlowControl2.VirtualControlCount = Queue.Count; virtualFlowControl2.VirtualControlCount = Queue.Count;
} }