I have a background task (actually a Bluetooth device scan) that I have to wait completion.
To not forcing the user to wait for it, I coded it as a resumable sub, run it and, while it runs, perform some user interaction.
Dim BLEScan As Object 'for waiting on
BLEScan = Globals.bluetoothDevs.ScanBLE 'start background scanning
' ...
'user interaction code that have variable completion time
' ...
ToastMessage.ShowProgress("Scanning Bluetooth")
Wait For (BLEScan) Complete (success As Boolean)
ToastMessage.HideProgress
If the user completes the iteraction before the scan is completed, the Wait For works as intended, waiting for the sub to complete before proceeding.
If the user is slow and the resumable sub completes beforehand, the Wait For causes a crash with
Resumable sub already completed
What's the best way to deal with such a case?