Introduction
I am sharing here the code to call a console application from a web on a button click event. We can track the begin and end time of the application here.
The most important thing is we can also check whether the process is already running priorly or not.
The code snippet is as follows:
protected void btnStartProcess_Click(object sender, EventArgs e)
{
string filePath = @"C:\\Users\\arnav\\Desktop\\Phrase value Util\\abc.exe";
System.Diagnostics.ProcessStartInfo info =
new System.Diagnostics.ProcessStartInfo(filePath, "");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = info;
while (!IsProcessOpen("abc"))
{
p.Start();
string startTime = p.StartTime.ToString();
Response.Write(startTime);
}
string endTime = p.ExitTime.ToString();
Response.Write(endTime);
}
public bool IsProcessOpen(string name)
{
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Contains(name))
{
return true;
}
}
return false;
}
Here we can check the process is priorly open or not from web itself. This will help us in finding a single application running instances. It prevents the multiple instances at server.
In this way we can call a console application from a web application using a button click event. Hopw this will be helpfull to all.