I'm trying to write a function that is finishing my running Process and afterwards opening a batch file. The batch file is just closing my c# .exe and deleting the contents of the txt file. The function i call is triggered on change in a txt file. So when it's triggered i read the number wich is written in the txt file and than calling the .bat. But now the Problem after "opening" the .bat my programm is not be closed directly. The function is jumping back to where i'm reading out of the txt file. But as i deleted the content of the .txt there is a Error coming up.
private void OnChangedUpdate(object sender, FileSystemEventArgs e)
{
string[] lines = new string[1];
lines = System.IO.File.ReadAllLines(@"Dateien/DB/Status/CheckUpdate.txt");
if (lines[0] == "1") // Update um 23:30 ausführen
{
TimerStartUpdate();
}
else if (lines[0] == "2") // Update direkt ausführen
{
OnTimedEventUpdateDirect();
return;
}
else
{
MessageBox.Show("Updated failed. Please contact supervisor");
}
}
private void OnTimedEventUpdateDirect()
{
// Prozess beenden
Processfinish_Update();
// Alles schreiben
// Bat Datei öffnen
Process P = new Process();
P.StartInfo.FileName = "UpdateBDE.bat";
P.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
P.Start();
// Theorie BDE wieder aufmachen in Batdatei
}
The batch file:
TASKKill /IM BDE.exe
echo.>Dateien/DB/Status/CheckUpdate.txt
CodePudding user response:
Add P.WaitForExit(); to wait the launched process to finish.
CodePudding user response:
I found the error myself :))
In the observe() which calls my OnChangedUpdate, I'm also checking Lat Acces and more. So as i change somethin from out the Batch script the function must be triggered again.