How to wait for the current lightning creation process to finish when pressing the cancel button?

eshesh michael 40 Reputation points

The logic: When clicking the btnStartProcessing_Click it will start processing next click will stop processing. if clicking the button to stop the processing and it's in the middle of processing a lightning then it will wait for the current lightning processing to finish and then will end the overall process.

This is working fine when clicking the button in the middle of processing the first lightning or the third lightning fourth fifth sixth any lightning except the second one.

I can tell why when I click the cancel button and it's processing the second lightning and it's only the second one then when it's finishing processing the second lightning instead stop and cancel all the operation it keeps going on to the next lightnings.

The problem is only with the second lightning process.

The code is a bit long, but everything is connected.

The top of form1:

The btnStartProcessing_Click event:

The ProcessingLightning method:

and the ProcessVideoFramesAsync method:

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,633 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,002 questions
{count} votes