I've created an app with a process. If the user tries to close the form when the process is busy they are prompted and asked if they'd like to wait or end. If they choose to wait then raise a cancel flag is set and checked in the BGW which will come to end after the current task.
The problem is how to deal with if they still like to end. My process is zipping up files. If the process is on a large zip and the user wouldn't like to wait then I need to kill the BGW and then clean up i.e. delete the incomplete zip file. I've written this:
Else
' If cancel selected...
' Forces backup to end.
???
' Deletes incomplete backup.
If My.Computer.FileSystem.FileExists(currentBackup1) Then
My.Computer.FileSystem.DeleteFile(currentBackup1)
End If
End If
I've tried deleting the file in my form close sub, but the BGW still has access and I have an exception that the file is in use. So either I need to kill the BGW or be able to delete a file in use just before the form closes. Can anyone help please? Thanks.