It should work as is because ClosedXML only locks the file when it reads or writes to it.
First try getting rid of all those .Dispose(), they're not doing anything in your case.
If that doesn't work you could try putting the workbook/file creation and the file delete in two different functions, then call both from the click event.
First try getting rid of all those .Dispose(), they're not doing anything in your case.
If that doesn't work you could try putting the workbook/file creation and the file delete in two different functions, then call both from the click event.