Extract the file before the program is completely closed
I have a program that integrates your library. My program performs some tasks when it is completely closed (takes about 2-5 seconds). It seems that the new version of the unzip command is executed before my program is completely closed, resulting in the failure to update the new version.
Content of the log ZipExtractor.log:
10 tháng 9 2024 4:05:30 CH
ZipExtractor started with following command line arguments.
[0] c:\users\<user>\appdata\local\temp\zipextractor.exe
[1] --input
[2] c:\users\<user>\appdata\local\temp\publish.zip
[3] --output
[4] d:\target
[5] --current-exe
[6] d:\target\switcher.exe
[7] --clear
BackgroundWorker started successfully.
Removing all files and folders from "D:\target\".
Removing a file located at "D:\target\clear.bat".
Removing a file located at "D:\target\D3DCompiler_47_cor3.dll".
System.UnauthorizedAccessException: Access to the path 'D:\target\D3DCompiler_47_cor3.dll' is denied.
at ZipExtractor.FormMain.<>c__DisplayClass4_0.<FormMain_Shown>b__2(Object _, RunWorkerCompletedEventArgs eventArgs)
I hope you can look into this issue, run some tests, and fix it if necessary.
Thank you.
Ah yeah, I have the same problem. Whwn I use this custom event:
AutoUpdater.ApplicationExitEvent += AutoUpdater_ApplicationExitEvent;
private void AutoUpdater_ApplicationExitEvent()
{
Text = @"Closing application...";
Thread.Sleep(10000);
Application.Exit();
}
And I wait 10 seconds then I get the same error as you :(. I thought i've used in the wrong way.
ZipExtractor only waits for the main executable to close. If any other thing is holding a lock on the file, it won't be able to overwrite it. Can you tell me how are you performing the operation after application is closed?
In my opinion it does not wait until the main process is closed.
For instance when the updater finds an update: It's calling this event:
private void AutoUpdater_ApplicationExitEvent()
{
log.Debug("AutoUpdater_ApplicationExitEvent");
Thread.Sleep(10000);
log.Debug("Shutdown");
Current.Shutdown();
}
Now the program crashes because the Zip Extractor cant access the files because the program is still open.
I tested it on AutoUpdaterTest application inside the project, and it does wait for it. You can see it in code here. Can you try reproducing it on test project?
Hey, I created a test app and it worked :). I found out, that I was still on version 1.8.5. Now after updating the package it's working :).
You are awesome! 🙏
Sorry for the delayed response. My application encountered this issue when using version 1.8.5. After I updated to the new version 1.9.2, the issue no longer occurred. I'm not sure why.
Luckily, we can still alert users through the changelog webview.
Thank for your support.