Task queues in Multi-Server Mode Vault Application Framework applications

Legacy functionality

You are not viewing the latest version of this guidance. The information on this page is for legacy reference only, and should not be used with new M-Files developments. Show me the latest version

Compatibility

The content of this page can only be used if the following condition(s) are all met:

  • You must target the Vault Application Framework 2.2 or higher.

Overview

Task queues should be used in place of background operations when targeting Multi-Server Mode. This ensures that the operations are correctly processed when multiple M-Files servers may be connected to a vault.

The VAF Extensions library contains various helper methods for creating task queues.

Task queue types

Before creating a task queue, you must decide which type of queue is most appropriate for your situation: sequential, concurrent, or broadcast.

Sequential task queues

Tasks added to a sequential task queue will be processed in the order in which they were added; if tasks 1, 2, then 3 are added to the queue then the tasks will be processed one at a time and the processing order is guaranteed to be 1, 2, 3.

Concurrent task queues

Tasks added to a concurrent task queue can be assigned to any number of M-Files servers in the Multi-Server Mode configuration, may be processed concurrently, and without regard for the order in which they were added to the queue.

Broadcast task queues

Broadcast task queues are used to broadcast information generated in one M-Files server to all others in the Multi-Server Mode configuration. This can be used to send commands for other servers to update any cached information they may have, for example.

Migration of background processes to a recurring task

The concept of a background operation is more awkward in situations where more than one M-Files server is involved. As a Vault Application Framework background operation is simply a .NET Task, and vault actions performed by the background operation are typically run outside of a transaction, it is fairly easy for background operations to cause unexpected side-effects within the vault.

To resolve this, a recurring task should be used instead.

Reporting task status

It’s important that long-running tasks periodically report their status back to the system. This can be done by calling TaskProcessorBase<T>.UpdateTaskInfo, providing the current task’s state and any textual remarks (e.g. the percentage complete):

this.SequentialProcessor.UpdateTaskInfo
(
	job,
	MFTaskState.MFTaskStateInProgress,
	$"The process is {percentageComplete}% complete.",
	false
);

The progress can be reported back as frequently as makes sense, but it is recommended that long-running tasks report their status at least every 30 seconds.