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) { // We can configure the path from the web config file too string filePath = @"C:\\Users\\sisirp\\Desktop\\Phrase Translation Util\\PhraseTranslationUtil.exe"; System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(filePath, ""); //System.Diagnostics.Process p = System.Diagnostics.Process.Start(info); System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo = info; //while (p.Responding) while (!IsProcessOpen("PhraseTranslationUtil")) //Here we can check for the application is running priorly or not { p.Start(); string startTime = p.StartTime.ToString(); //This line gets the start time of the process Response.Write(startTime); } string endTime = p.ExitTime.ToString(); //This line gets the end time of the process Response.Write(endTime); } public bool IsProcessOpen(string name) { //here we're going to get a list of all running processes on foreach (Process clsProcess in Process.GetProcesses()) { if (clsProcess.ProcessName.Contains(name)) { return true; } } return false; }