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

eshesh michael 60 Reputation points
2023-09-07T13:08:57.5733333+00:00

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:

Developer technologies | Windows Forms
Developer technologies | C#
Developer technologies | C#
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.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.