ASP.NET with VB.NET – execute long running duration process in the background with executable (exe)


There is a need to perform long running report generation in an page on an ad-hoc basis. The report has to run behind the scene and allows for picking up later when the report generation is finished.



The .NET System.Diagnostics.Process can be used by an web page to run executable on the server behind the scene. On the page, you can write code to start your exe like so:

Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
myProcess.StartInfo.WorkingDirectory = Me.Request.MapPath(“~/bin”)
myProcess.StartInfo.FileName = Me.Request.MapPath(“~/bin/report.exe”)
myProcess.StartInfo.Arguments = “1”

Report.exe in this case is the report executable built to perform the long running report. The exe must handle properly the releasing of resources after its execution to avoid unwanted errors or memory issues.

The .Arguments parameter is the command-line arguments of the exe which in this case “1” is simply a report number to run. In this example, it can be the 1st report of the many long running reports that the report.exe is built to generate.

Once .Start() is triggered, the process will set off to run behind the scene. Upon completion, the report will be placed in a directory. An page can then be programmed to list the reports from that directory for downloading by the user from the web page.

A code segment can also be done to list currently running reports processes like so:

Dim mySB As StringBuilder = New StringBuilder()
For Each myP As System.Diagnostics.Process In System.Diagnostics.Process.GetProcessesByName(“report”)
mySB.Append(myP.ProcessName).Append(“: process id: “).Append(myP.Id)

You may in fact use the retrieved process to perform more functions, like stopping the reports generation, or checking how long the reports have been running.

The above solution only demonstrated the fundamentals to tackling the scenario. You can enhance the solution to cater to your specific needs.


Ad: Vodien: Affordable, Reliable and Professional Singapore Web Hosting
Vodien: Affordable, Reliable and Professional Singapore Web Hosting