Sdílet prostřednictvím


IUIThreadOperationExecutor Interface

Definition

Executes potentially long running operation on the UI thread and provides shared two way cancellability and wait indication.

public interface class IUIThreadOperationExecutor
public interface IUIThreadOperationExecutor
type IUIThreadOperationExecutor = interface
Public Interface IUIThreadOperationExecutor

Examples

A typical usage of IUIThreadOperationExecutor to execute a potentially long running operation on the UI thread is as follows:

[Import]
private IUIThreadOperationExecutor uiThreadOperationExecutor = null;
...
UIThreadOperationStatus status = _uiThreadOperationExecutor.Execute("Format document",
    "Please wait for document formatting...", allowCancel: true, showProgress: false,
    action: (context) => Format(context.UserCancellationToken));
if (status == UIThreadOperationStatus.Completed)...

Or alternatively

using (var context = _uiThreadOperationExecutor.BeginExecute("Format document",
    "Please wait for document formatting...", allowCancel: true, showProgress: false))
{
    Format(context);
}

private void Format(IUIThreadOperationContext context)
{
    using (context.AddScope(allowCancellation: true, description: "Acquiring user preferences..."))
    {...}
}

Remarks

Visual Studio implementation of this service measures operation execution duration and displays a modal wait dialog if it takes too long. The wait dialog describes operation to the user, optionally provides progress information and allows user to cancel the operation if it can be cancelled. Components running in the operation can affect the wait dialog via IUIThreadOperationContext provided by this service.

This is a MEF component and should be imported for consumptions as follows:

[Import]
private IUIThreadOperationExecutor uiThreadOperationExecutor = null;

Host specific implementations of this service should be exported as follows:

[ExportImplementation(typeof(IUIThreadOperationExecutor))]
 [Name("Visual Studio UI thread operation executor")]
 [Order(Before = "default")]
 internal sealed class VSUIThreadOperationExecutor : IUIThreadOperationExecutor

All methods of this interface should only be called on the UI thread.

Methods

BeginExecute(String, String, Boolean, Boolean)

Begins executing potentially long running operation on the caller thread and provides a context object that provides access to shared cancellability and wait indication.

BeginExecute(UIThreadOperationExecutionOptions)

Begins executing potentially long running operation on the caller thread and provides a context object that provides access to shared cancellability and wait indication.

Execute(String, String, Boolean, Boolean, Action<IUIThreadOperationContext>)

Executes the action synchronously and waits for it to complete.

Execute(UIThreadOperationExecutionOptions, Action<IUIThreadOperationContext>)

Executes the action synchronously and waits for it to complete.

Applies to