Table of Contents

Class AsyncHelper

Namespace
Vintagestory.API.Util
Assembly
VintagestoryAPI.dll

A class to provide general helper functions for multi-threaded (asynchronous) operations

public class AsyncHelper
Inheritance
AsyncHelper
Inherited Members
Extension Methods

Methods

CanProceedOnThisThread(ref int)

For situations where a task should proceed only if another thread is not already working on the same task on the same object. For example, a main thread and a worker thread both iterating through a list of objects to process, this will ensure each object is processed exactly once.
Both threads should call this method before proceeding to do the task, both using an int field in each object to mark when the work has started.

Optionally, the referenced field can be a volatile int. It is not necessary for it to be volatile for correct Interlocked operation, but it can be a good idea if the value will be set or read elsewhere in the calling code.

public static bool CanProceedOnThisThread(ref int started)

Parameters

started int

Pass by reference.
If this is volatile, it is safe to ignore the compiler warning "a reference to a volatile field will not be treated as volatile"

Returns

bool