I have test a small program.I have 3 executable Training_, Training_1 and Training_2.
Training_ is a code to put Training_1 at startUp windows and Training_1 have a Proses.Start to start Training_2 automatically.
I don't how to stop or close Training_2 using Proses.kill() in Training_1.
Thank.
form code;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace Training_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string myFavoritesPath = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
Start_1.OpenApplication(myFavoritesPath);
}
private void button1_Click(object sender, EventArgs e)
{
string myFavoritesPath_ = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
Start_1.StopApplication(myFavoritesPath_);
}
}
}
Class code
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
namespace Training_1
{
class Start_1
{
public static void OpenApplication(string myFavoritesPath)
{
try
{
using (Process myProcess = new Process())
{
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = "C:\\Users\\family\\Desktop\\Training_2.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public static void StopApplication(string myFavoritesPath_)
{
try
{
using (Process myProcess = Process.Start("C:\\Users\\family\\Desktop\\Training_2.exe"))
{
myProcess.Kill();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}