I read this article ( Failed to delete the file using streams ) about my problem, but it's getting harder for me.
My problem is very simple, I just want to delete this old file, if I run the "dlMoveNovaVersao" method, the file is usually deleted, but if I put it in a stream (for example, below), I got "You do not allow". Does anyone know what the problem is? (I want to use a stream).
private void verificaVersaoSupervisor_Tick(object sender, EventArgs e) { Thread threadConexao = new Thread(threadVerificaConexao); threadConexao.Start(); } public void threadVerificaConexao() { try { Dns.GetHostEntry("www.google.com.br"); if (verificaVersao()) { try { verificaKillSupervisor(); dlMoveNovaVersao(); Application.Exit(); } catch (Exception) { } } else { Application.Exit(); } } catch (Exception) { } } public void dlMoveNovaVersao() { WebClient webClient = new WebClient(); webClient.DownloadFile("Anywebsite", @"c:\temp\supervisor.exe); try { File.Delete(@"c:\Test\supervisor.exe);
Just describe the purpose, My program (Supervisor Starter) checks on the website if I have an old version of "Supervisor" running (using XML). If this is true, my "Supervisor Starter" checks if there is a process called "Supervisor" "start and kill after that" Supervisor Starter "download the new version and start it. (The program is small and the update does not take more than 4 seconds).
The problem starts when my "Supervisor Starter" tries to uninstall an old version of my program. If I use thread, I get "I do not have access to the file", if I use the same method in the Form class, the file will be deleted.
source share