Please note that you opened two instances of Training_2.exe in the original code. They have their own PIDs. When you use myProcess.Kill();
, it will only close the one opened in the StopApplication method.
Try this:
class Start_1
{
private static Process myProcess;
public static void OpenApplication(string myFavoritesPath)
{
try
{
myProcess = new Process()
...
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public static void StopApplication(string myFavoritesPath_)
{
try
{
myProcess?.Kill();
myProcess = null;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
This is just how the idea of Viorel-1 is used in your code.
I wanted to post it as a comment, but the characters exceeded the comment limit, so I had to post it as an answer.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.