I created a simple app with a button in the navbar that calls a function in the HomeController
.
The function executes a exe process in the server.
I would like to show something in the navbar that is showing if the function or process is still running or not.
The button calling the function is in the _Layout.cshtml
:
<span class="navbar-text">
<a class="btn btn-outline-success" type="button"
asp-controller="Home" asp-action="StartParser">Update Info</a>
</span>
In the HomeController
I created the function:
public IActionResult StartParser()
{
Process p = new Process();
p.StartInfo.FileName = @"C:\Parser\bin\Debug\Parser.exe";
p.StartInfo.Arguments = "Web";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += (sender, data) => Console.WriteLine(data.Data);
p.ErrorDataReceived += (sender, data) => Console.WriteLine(data.Data);
p.Start();
// p.WaitForExit();
return RedirectToAction("Index");
}
I thought about letting the process update a value in the db like a "isRunning" and then read it in the app but I don't like this solution because if the process gets terminated for some reason then the value will not be updated correctly.
Should I modify the function to be async and uncomment the p.WaitForExit();
?
In this scenario how can I "refresh" the Navbar (For example adding a text: "Process Running") when the function starts and refresh it again at the end?
Any other ideas are welcome!