BC Teardown #5: Long batch jobs freeze your users

BC Teardown #5: Long batch jobs freeze your users

The pain

Someone starts a price update or recalculation and their Business Central session is locked until it finishes.

Why it happens

The job runs in the user’s own session, in the foreground, so they cannot do anything else while it runs.

Before: Run it in the user's session

trigger OnAction()
begin
  Codeunit.Run(Codeunit::"DF Recalc Prices");
  // the user waits until it is done
end;

After: Hand it to a background session

trigger OnAction()
begin
  TaskScheduler.CreateTask(
    Codeunit::"DF Recalc Prices",
    0, true, CompanyName(),
    CurrentDateTime() + 1000);
  Message('Running in the background.');
end;

// Recurring? Schedule it as a
// Job Queue Entry instead.

The result

The work runs in the background. Users keep working, and recurring jobs run overnight with no one watching.

Tip: Add a failure codeunit so errors get logged instead of lost.

Download this teardown as a PDF


Got a Business Central problem like this? Free 30 minute review of your setup. Senior Microsoft certified developers, and you talk to the person writing the code. Contact Dataflow Solutions.