Background Job Starting External Process

Can a HangFire background job start an external process? For instance if I write a console app to process some data in my database, and I call it using a hangfire background task is that a use case that works?

If I schedule my job like this,

BackgroundJob.Schedule<AssetValuation>(x => x.StartAssetValuation("petermc", "password", "AT", "Signs"), TimeSpan.FromSeconds(10));

And the code to run the job looks like this,

public void StartAssetValuation(string username, string password, string database, string assetType)
        ProcessStartInfo pInfo = new ProcessStartInfo("calc");

        Process mProcess = new Process();
        mProcess.StartInfo = pInfo;

It all seems OK, but the WaitForExit doesn’t seem to wait. When I look in the dashboard the job is started and finished straight away instead of waiting for me to close the calc app.

If I run the code above in a console app it does wait.

I am hoping that running calc is the issue, and would like some confirmation that this is going to work when I write something proper in a console app.

Hi Peter

Did you find any solution to that? I am having the same problem.

I did get this working, and the issue described above seems to relate to the calc application.

When I wrote a small console application which does a Thread.Sleep, and called that from a wrapper similar to above it worked, and the WaitForExit did wait.

But have we tried this in production? No, we have not got that far yet.

Give it a try, I would like to hear how you get on.