I have an application (WPF) that has been running for about 2 months without any problems. I needed to make a change. When doing, in the line where I should choose a folder to save the result of my application, the application hangs (seems to get lost). This started yesterday. I went home and today, in the first hour, I was able to make it work. After that it worked, from there it did not work anymore, again giving the error. If you comment the line and fixed a folder, the application works (obvious). This is the line that hangs:
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
.
Below the complete method code:
private void CriarZip()
{
string path_destino = string.Empty;
string path_files = caminho_original + @"\Destino\Temp";
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
fbd.Description = "Selecione a pasta para armazenar o arquivo zipado.";
fbd.RootFolder = Environment.SpecialFolder.MyComputer;
fbd.ShowNewFolderButton = true;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
path_destino = fbd.SelectedPath;
List<string> _filesDiretory = new List<string>();
string nome_arquivo = nome_arquivo_zip + ".zip";
if (!nome_arquivo.Contains(".zip"))
{
MessageBox.Show("O nome do arquivo deve possuir a extensão .zip");
return;
}
try
{
string[] files_new = Directory.GetFiles(path_files, "*", SearchOption.AllDirectories);
string[] folder_new = Directory.GetDirectories(path_files, "*", SearchOption.AllDirectories);
CriaPastaFarmInterna();
CriaPastaFarmExterna();
//Deleto os arquivo que não estão na Farm Externa
foreach (var file in files_new)
{
string t = string.Empty;
int pos = file.IndexOf(dirInicio);
if (pos > 0)
{
t = file.ToString().Substring(pos, file.Length - pos);
bool bListaArquivo = (from b in listaArquivosForaFarmExterna
where b.Contains(t)
select b).Count() > 0 ? true : false;
if (bListaArquivo)
File.Delete(file);
}
else
{
t = Path.GetFileName(file);
arquivos.Add(t);
}
}
LimpaPastaWeb();
DeletaPastaFarmExterna();
//Adiciono arquivos que estão dentro da pasta base apenas
foreach (var file in Directory.GetFiles(path_files))
{
arquivos.Add(file);
}
//Aqui pego as pastas com arquivos que serão zipadas
foreach (var file in Directory.GetDirectories(path_files))
{
arquivos.Add(file);
}
string localNomeDestinoZIP = path_destino + "\" + nome_arquivo;
if (arquivos.Count() > 0)
{
processaDiretorio(path_files);
ZipUnzip.CriarArquivoZip(arquivos, localNomeDestinoZIP);
MessageBox.Show("Os arquivos selecionados foram compactados na pasta \n\n " +
localNomeDestinoZIP);
}
else
MessageBox.Show("Não há a pasta para ser compactada.");
}
catch (Exception ex)
{
MessageBox.Show("Ocorreu um erro ao criar arquivo ZIP \n\n " + ex.Message);
//zipgif.Visibility = System.Windows.Visibility.Hidden;
}
finally
{
DeletarPastaTrabalho(caminho_original);
//zipgif.Visibility = System.Windows.Visibility.Hidden;
Application.Current.Shutdown();
}
}