Система прекращает импорт
I have a system that looks in a client informed folder for OpenFileDialog for all XML, then reads them, and then imports the data into a SQL Server database. The problem is that after a while, it stops importing, and the system hangs, but in monitoring everything is still running. If I import one by one, I can import them all, but the system must be importing hundreds of XML at a time. Another problem is a method that returns true or false when XML has already been imported, if I start debugging, the method returns false, if I let it run without delegation, it returns true.
Что я уже пробовал:
//Counts how many files there are in the path of the first XML folder int cte = 0; if (Directory.Exists(caminhocte)) { foreach (string filePath in Directory.EnumerateFiles(caminhocte, "*.xml", SearchOption.AllDirectories)) { cte++; } } //Counts how many files there are in the path of the second XML folder int nfe = 0; if (Directory.Exists(caminhonfe)) { foreach (string filePath in Directory.EnumerateFiles(caminhonfe, "*.xml", SearchOption.AllDirectories)) { nfe++; } } //Displays a message with how much XML will be imported, and asks if he wants to continue with the import MessageBoxButtons buttonn = MessageBoxButtons.YesNo; MessageBoxIcon iconn = MessageBoxIcon.Information; string messagen = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}", "Detalhes: ", Environment.NewLine, "Numero de XML na pasta CTE: ", cte, Environment.NewLine, "Numero de XML na pasta NFE: ", nfe, Environment.NewLine, "Deseja continuar com a importação?"); string titlen = "Aviso"; DialogResult result = MessageBox.Show(messagen, titlen, buttonn, iconn); //If you do not want to continue importing, the system returns if (result == DialogResult.No) { return; } int ctes = 0; int ctee = 0; if (Directory.Exists(caminhocte)) { ImportaXML(caminhocte, "CTE"); ctes = xmlimportsucess; ctee = xmlimporterror; } int nfes = 0; int nfee = 0; if (Directory.Exists(caminhonfe)) { ImportaXML(caminhonfe, "NFE"); nfes = xmlimportsucess; nfee = xmlimporterror; } xmlimporterror = 0; xmlimportsucess = 0; //Build a message that will be generated at the end of the process in txt form. string messagesucess = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}{16}", "Informações da importação do CTE", Environment.NewLine, "CTE importado com sucesso: ", ctes, Environment.NewLine, "CTE não importado(Erro): ", ctee, Environment.NewLine, "Informações da importação da NFe", Environment.NewLine, "NFe importada com sucesso: ", nfes, Environment.NewLine, "NFe não importado(Erro): ", nfee, Environment.NewLine, "-----------------------------------" ); MessageBoxButtons buttonF = MessageBoxButtons.OK; MessageBoxIcon iconF = MessageBoxIcon.Information; string messageF = "Arquivo de Registro do log foi gerado com sucesso."; string titleF = "Aviso"; MessageBox.Show(messageF, titleF, buttonF, iconF); //Create folder and log txt file registrarLog(messagesucess, "", "Reg"); GC.Collect(); //This method will get the path and type case, in the DirectXML class it will read the XML and see if it is a CTE or NFE and will import the XML information. //If it gives an error, it will log a log. void ImportaXML(string caminho, string tipo) { xmlimportsucess = 0; xmlimporterror = 0; foreach (string filePath in Directory.EnumerateFiles(caminho, "*.xml", SearchOption.AllDirectories)) { try { DirecionarXML dir = new DirecionarXML(); dir.direcionarXML(filePath, "", tipo); xmlimportsucess++; } catch (Exception ex) { registrarLog(ex.Message, filePath, "Err"); xmlimporterror++; } } }