Tekniq mark
Tekniq SDK Docs

LongRunningTaskManager

Run longer tasks without blocking the UI and provide progress feedback

Progress orchestration Run longer tasks without blocking the UI and provide progress feedback
Audience: Internal + External Module: Framework Use case: Background work + progress

Purpose

LongRunningTaskManager is the place to run heavier actions without blocking the UI. It is especially useful for imports, plugin creation, exports and other repetitive loops where progress should be shown to the user.

Typical usage

[CommandHandler]
public async void InsertPlugins()
{
    try
    {
        if (PurchaseOrders == null || PurchaseOrders.Any() == false)
        {
            return;
        }

        await LongRunningTaskManager.Instance.RunAsync(token =>
        {
            new PluginCreator(PurchaseOrders, PurchaseOrder).Create();
        });

        RaisePropertyChanged(nameof(PurchaseOrder));
    }
    catch (Exception e)
    {
        this.LogError($"Error in {nameof(InsertPlugins)} in {nameof(DashboardControlViewModel)}", e);
    }
}

Progress scope pattern

var progress = LongRunningTaskManagerExtensions.Scope(20, 90, _purchaseOrders.Count);

for (var i = 0; i < _purchaseOrders.Count; i++)
{
    progress.Step($"Plaatsen van {purchaseOrderLine.ProductOption.Name}");
}

progress.Done();
This pattern works well when the first part of the total progress belongs to preparation, the middle band belongs to the loop itself, and the final percentage is reserved for finishing steps.