private static bool Handler(CtrlType sig) { newThread.Abort(); Connecteur_Info.Custom.Batch_Interrup interrup = new Connecteur_Info.Custom.Batch_Interrup(); interrup.interruption(); //do your cleanup here Thread.Sleep(5000); //simulate some cleanup delay Console.WriteLine(""); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////// Fichier_De_Nettoyage.dll /////////////// /// string logDirectoryName_general = Directory.GetCurrentDirectory() + @"\" + "LOG"; string logDirectoryName_import = Directory.GetCurrentDirectory() + @"\" + "LOG" + @"\" + "LOG_Import"; Fichier_De_Nettoyage.FichierDeNettoyage clean = new Fichier_De_Nettoyage.FichierDeNettoyage(); string[,] paths = new string[4, 2] { { "general_logs", logDirectoryName_general }, //log files { "import_logs", logDirectoryName_import }, //log files { "import_files_success", Directory.GetCurrentDirectory() + @"\Success File" }, //fichier import success { "import_files_error", Directory.GetCurrentDirectory() + @"\Error File" } //fichier import erreur }; clean.startClean(paths); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Console.WriteLine("Cleanup complete !"); Init.Init init = new Init.Init(); init.setDisplay(false); Console.WriteLine("General Config reseted!"); //allow main to run off exitSystem = true; //shutdown right away so there are no lingering threads Environment.Exit(-1); return(true); }
private static bool Handler(CtrlType sig) { newThread.Abort(); Connecteur_Info.Custom.Batch_Interrup interrup = new Connecteur_Info.Custom.Batch_Interrup(); interrup.interruption(); //do your cleanup here Thread.Sleep(5000); //simulate some cleanup delay Console.WriteLine(""); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////// Fichier_De_Nettoyage.dll /////////////// /// Fichier_De_Nettoyage.FichierDeNettoyage clean = new Fichier_De_Nettoyage.FichierDeNettoyage(); clean.startClean(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Console.WriteLine("Cleanup complete !"); /* * Init.Init init = new Init.Init(); * init.setDisplay(false); */ Console.WriteLine("General Config reseted!"); //allow main to run off exitSystem = true; //shutdown right away so there are no lingering threads Environment.Exit(-1); return(true); }
private void button17_Click(object sender, EventArgs e) { Forms.ProgressDialog progressDialog = new Forms.ProgressDialog(); // Initialize the thread that will handle the background process Thread backgroundThread = new Thread( new ThreadStart(() => { //Loading General Settings if (progressDialog.InvokeRequired) { progressDialog.BeginInvoke(new System.Action(() => progressDialog.Text = "Nettoyage des logs....")); } for (int n = 0; n < 30; n++) { Thread.Sleep(1); progressDialog.UpdateProgress(n); } //Create log file string clean_file_log = Directory.GetCurrentDirectory() + @"\LOG\" + string.Format("LOG_Clean_{0:dd-MM-yyyy_HH.mm.ss}.txt", DateTime.Now); try { var logFile_clean = File.Create(clean_file_log); using (StreamWriter writer = new StreamWriter(logFile_clean)) { // Init database && tables Database.Database db = new Database.Database(); db.initTables(writer); writer.Flush(); Fichier_De_Nettoyage.FichierDeNettoyage clean = new Fichier_De_Nettoyage.FichierDeNettoyage(); writer.Flush(); for (int n = 30; n < 60; n++) { Thread.Sleep(1); progressDialog.UpdateProgress(n); } clean.startClean(writer); writer.Flush(); writer.Close(); } } catch (Exception ex) { MessageBox.Show("ERROR[Clean 1] : " + ex.Message, "Erreur!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } bool ok = false; for (int n = 60; n < 100; n++) { Thread.Sleep(1); progressDialog.UpdateProgress(n); if (n == 99) { ok = true; } ; } // Close the dialog if it hasn't been already if (ok && progressDialog.InvokeRequired) { progressDialog.BeginInvoke(new System.Action(() => progressDialog.Close())); } } )); // Start the background process thread backgroundThread.Start(); // Open the dialog progressDialog.ShowDialog(); }