Share via


SuggestionManagerBase.EnqueueAction(String, Func<Task>, Object) Method

Definition

Enqueue action to run after previously enqueued actions have completed

public virtual void EnqueueAction (string description, Func<System.Threading.Tasks.Task> action, object? tag = default);
abstract member EnqueueAction : string * Func<System.Threading.Tasks.Task> * obj -> unit
override this.EnqueueAction : string * Func<System.Threading.Tasks.Task> * obj -> unit
Public Overridable Sub EnqueueAction (description As String, action As Func(Of Task), Optional tag As Object = Nothing)

Parameters

description
String
action
Func<Task>
tag
Object

Remarks

This method must be called from the UI thread.

if tag is non-null, then only the last action in the queue with that tag will run (if, when an action is dequeued, there is a subsequent action in the queue with the same tag, then the first action is discarded).

The intent of this method is to serialize user actions -- that happen on the UI thread -- with whatever might be happening in the background. For example,

The user types 'C'
Inline Completions reacts to the C by requesting a prediction.
IntelliSense reacts to the C by starting IntelliSense

The following three events then happen happen nearly simultaneously on their respective threads:
  IntelliSense displays the IntelliSense list, selecting Console by default.
  The user types 'o'.
  The prediction completes on a background thread and generates a prediction of "Console.WriteLine();"

We need to ensure the suggestion service completely processes each event completely before starting the next event. The order in which the
events are processed needs to match the order in which they were generated.

If we tried the last steps without serialization (e.g. allow the IntelliSense event to be processed before the events associated with displaying the prediction are processed), things might not update correctly.

should never call EnqueueAction(String, Func<Task>, Object).

The pattern to use this method is to call it only when responding to UI events (dispatching to a background thread if needed).

Applies to