Condividi tramite


BindingBase.EnableCollectionSynchronization Method

Definition

Starts synchronization on the collection by using callback and context.

public:
 static void EnableCollectionSynchronization(System::Collections::IEnumerable ^ collection, System::Object ^ context, Microsoft::Maui::Controls::CollectionSynchronizationCallback ^ callback);
public static void EnableCollectionSynchronization (System.Collections.IEnumerable collection, object context, Microsoft.Maui.Controls.CollectionSynchronizationCallback callback);
static member EnableCollectionSynchronization : System.Collections.IEnumerable * obj * Microsoft.Maui.Controls.CollectionSynchronizationCallback -> unit
Public Shared Sub EnableCollectionSynchronization (collection As IEnumerable, context As Object, callback As CollectionSynchronizationCallback)

Parameters

collection
IEnumerable

The collection that will be read or updated.

context
Object

The context or lock object that will be passed to callback. May be null.

callback
CollectionSynchronizationCallback

The synchronization callback.

Remarks

Application developers implement callback and pass it to the EnableCollectionSynchronization(IEnumerable, Object, CollectionSynchronizationCallback) method to enable correct multithreaded access to collection. After synchronization is enabled, the Microsoft.Maui.Controls framework passes an access method, context, and a bool that indicates whether write access is needed, to the application developer's implementation of CollectionSynchronizationCallback each time that the framework needs to modify the collection in a multithreaded environment. The application developer's implementation should decide, based on the context object (which may be merely a locking object or the object on which the collection lives) and the value of the writeAccessbool parameter, whether or not to lock while calling accessMethod.

Because Microsoft.Maui.Controls maintains a weak reference to collection, application developers do not need to call DisableCollectionSynchronization(IEnumerable) to aid in garbage collection.

Applies to